I think this is a simple Q but I cannot get the syntax right. I want to specify the node name and get its contents. I do not want to loop through and grab the contents of all child nodes - which the code below is doing fine. I want to replace the inner loop by specifying the node name (name, description) - Everything I try returns an obj ref error. Can someone please point me in the right direction? Many thanks - JoBean3
'CODE BEHIND MY ASPX PAGE============
Private m_doc As New XmlDocument
m_doc.Load("c:\myXMLDoc.xml")
Dim xmlNodes As XmlNodeList = m_doc.DocumentElement.ChildNodes
Dim siteNode As XmlNode
For Each siteNode In xmlNodes
Dim propNode As XmlNode
For Each propNode In siteNode
'returns all props for a site node
Response.Write(propNode.InnerText & "<br>")
Next propNode
Next siteNode
'XML FILE CONTENTS==============
<?xml version="1.0" encoding="utf-8" ?>
<MyList>
<Site>
<name>Name1</name>
<description>Desc1</description>
</Site>
<Site>
<name>Name2</name>
<description>Desc2</description>
</Site>
</MyList>
'RESULTS OF EXECUTING CODE SNIPPET==========
Returns:
Name1
Desc1
Name2
Desc2
'CODE BEHIND MY ASPX PAGE============
Private m_doc As New XmlDocument
m_doc.Load("c:\myXMLDoc.xml")
Dim xmlNodes As XmlNodeList = m_doc.DocumentElement.ChildNodes
Dim siteNode As XmlNode
For Each siteNode In xmlNodes
Dim propNode As XmlNode
For Each propNode In siteNode
'returns all props for a site node
Response.Write(propNode.InnerText & "<br>")
Next propNode
Next siteNode
'XML FILE CONTENTS==============
<?xml version="1.0" encoding="utf-8" ?>
<MyList>
<Site>
<name>Name1</name>
<description>Desc1</description>
</Site>
<Site>
<name>Name2</name>
<description>Desc2</description>
</Site>
</MyList>
'RESULTS OF EXECUTING CODE SNIPPET==========
Returns:
Name1
Desc1
Name2
Desc2