Get Xml attribute

  • Thread starter Thread starter Aaron
  • Start date Start date
A

Aaron

<xml>
<test attrib1="hello" attrib2="world">textValue</test>
</xml>

I need some help getting the values of attrib1, attrib2 and the test tag.
the output should be:
hello
world
textValue

XmlDocument doc = new XmlDocument();
doc.Load(url);
XmlNode docElement = doc.DocumentElement;
XmlAttributeCollection tagAttribute = docElement.Attributes;

I got to this far but not sure what to do next

Thanks in advance

Aaron
 
Aaron said:
<xml>
<test attrib1="hello" attrib2="world">textValue</test>
</xml>

I need some help getting the values of attrib1, attrib2 and the test tag.
the output should be:
hello
world
textValue

XmlDocument doc = new XmlDocument();
doc.Load(url);
XmlNode docElement = doc.DocumentElement;
XmlAttributeCollection tagAttribute = docElement.Attributes;

I got to this far but not sure what to do next

Thanks in advance

Aaron

XmlDocument doc = new XmlDocument();
doc.Load(url);

XmlNode nd = doc.SelectSingleNode("/xml/text");
string t1 = nd.Attributes["attrib1"].Value; // "hello"
string t2 = nd.Attributes["attrib1"].Value; // "world"
string t3 = nd.InnerText; // "textValue"


Hans Kesting
 
Back
Top