简体   繁体   中英

XML having tags within multiple tag

I am parsing the xml but i can't parse the xml tags which are within and another tags. Here is the XML structure.

 <value>
<records>
  <product>
      <product_id>30</product_id>
      <product_name>Cotton Selvets</product_name>
      <product_imagepath>1529658805.jpg</product_imagepath>
      <product_description/>
      <product_basicprice/>
      <category_id>7</category_id>
      <product_status>Active</product_status>
      <product_lastupdate>2018-06-22</product_lastupdate>
  </product>
  <attributename>
        <product_id>30</product_id>
         <attribute_name>Colour</attribute_name>
         <attribute_id>8</attribute_id>
         <attributevalue>
              <product_id>30</product_id>
              <product_retaillerprice/>
              <attribute_id>8</attribute_id>
              <attributevalue_id>38</attributevalue_id>
               <attribute_value>Blue</attribute_value>
          </attributevalue>
   </attributename>
   <attributename>
           <product_id>30</product_id>
           <attribute_name>Size</attribute_name>
           <attribute_id>1</attribute_id>
           <attributevalue>
                <product_id>30</product_id>
                <product_retaillerprice/>
                <attribute_id>1</attribute_id>
                <attributevalue_id>1</attributevalue_id>
                <attribute_value>4x6</attribute_value>
           </attributevalue>
           <attributevalue>
                 <product_id>30</product_id>
                 <product_retaillerprice/>
                 <attribute_id>1</attribute_id>
                 <attributevalue_id>16</attributevalue_id>
                 <attribute_value>Basket</attribute_value>
           </attributevalue>
    </attributename>
</records>
</value>

attributename display in textview and if attributebname is color only that attributevalue display in spinner but my problem is all attribute value is disply in all spinner.my coding is below...

 try {
                if (response.length() > 0) {
                   /* int code = Integer.parseInt(XMLManualParser.getTagValue(ConstantUrl.TAG_CODE, response));
                    String msg = XMLManualParser.getTagValue("message", response);
                    if (code == 1) {*/
                    ProductList.clear();
                    ArrayList<String> prodcuts = XMLManualParser.getMultipleTagList("product", response);
                    for (int i = 0; i < prodcuts.size(); ++i) {
                        String responseContent = prodcuts.get(i);
                        Attribute attribute = new Attribute();
                        attribute.setProductname(XMLManualParser.getTagValue("product_name", responseContent));
                        attribute.setProductimagepath(XMLManualParser.getTagValue("product_imagepath", responseContent));
                        attribute.setProductdesc1(XMLManualParser.getTagValue("product_description", responseContent));
                        attribute.setProductbasicprize(XMLManualParser.getTagValue("product_basicprice", responseContent));
                        attribute.setProduct_id(Integer.parseInt(XMLManualParser.getTagValue("product_id", responseContent)));
                        ProductList.add(attribute);
                    }
                    attributenamearraylist.clear();
                    ArrayList<String> attributenamelist = XMLManualParser.getMultipleTagList("attributename", response);
                    for (int i = 0; i < attributenamelist.size(); ++i) {
                        String responseContent = attributenamelist.get(i);
                        attribute = new Attribute();
                        attribute.setAttr_name(XMLManualParser.getTagValue("attribute_name", responseContent));
                        attribute.setAttrebute_id(XMLManualParser.getTagValue("attribute_id", responseContent));
                        attributevaluearraylist.clear();
                        spinnerlist.clear();
                        ArrayList<String> attributevaluelist = XMLManualParser.getMultipleTagList("attributevalue", responseContent);
                        for (int j = 0; j < attributevaluelist.size(); ++j) {
                            String responsecontent = attributevaluelist.get(j);
                            Attribute attr = new Attribute();
                            attr.setAttr_value(XMLManualParser.getTagValue("attribute_value", responsecontent));
                            attr.setAttrebute_id(XMLManualParser.getTagValue("attribute_id", responsecontent));
                            attr.setDealer_prize(XMLManualParser.getTagValue("product_dealerprice", responsecontent));
                            attr.setRetailer_prize(XMLManualParser.getTagValue("product_retaillerprice", responsecontent));
                            attributevaluearraylist.add(attr);
                        }
                        attributenamearraylist.add(attribute);
                        Log.d("arraylistsize", attributevaluearraylist.size() + "");
                    }

                   /* } else {
                        Toast.makeText(ProductDescriptionActivity.this, msg, Toast.LENGTH_SHORT).show();
                    }*/
                    attribute_adapter.notifyDataSetChanged();
                }
            } catch (
                    Exception e)

            {

            }
            pdLoading.dismiss();

Don't make an XML parser yourself.

Use JDOM 2. Or any other existing XML parser if you like to make your life difficult.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM