1

I'll do my best to make this as clear as I can.

XmlNodeList ZONE = nodRoot.SelectNodes("CATALOG/PLANTS/ZONE");

This allows me to search for Plants in Zone 4. When I find one, I want to be able to get the ID # from the attribute above. I can't figure out how to get this. I've tried

I have code doing this.

string ID = null;
 foreach(XmlNode xmlNodeComplex in ZONE)
      {
        if(xmlNodeComplex.InnerText == "4")
            {
             ID = xmlNodeComplex.ParentNode.InnerText;
             .....
            }
       ....
      }

This will set the string ID to "PLANT". I can't find the right path to get to the ID attribute.

<CATALOG>
  <PLANT ID = "821">
     <COMMON>Bloodroot</COMMON>
     <BOTANICAL>Sanguinaria canadensis</BOTANICAL>
     <ZONE>4</ZONE>
     <LIGHT>Mostly Shady</LIGHT>
     <PRICE>$2.44</PRICE>
     <AVAILABILITY>031599</AVAILABILITY>
  </PLANT>
</CATALOG>

I want ID to = 821

Piper
  • 55
  • 6
  • Try looking at [this solution](http://stackoverflow.com/questions/1600065/how-to-read-attribute-value-from-xmlnode-in-c). – Tim Sexton Aug 06 '14 at 12:30

1 Answers1

1

Can you give try to the code below:

ID = xmlNodeComplex.ParentNode.Attribute["ID"].Value; 
Karol S
  • 9,028
  • 2
  • 32
  • 45
Neel
  • 11,625
  • 3
  • 43
  • 61