VB.NET: Get the Attribute and Text out from Xml

toytoy

Well-known member
Joined
Jul 16, 2004
Messages
46
Programming Experience
1-3
Say I have this Xml taken as an example:

VB.NET:
<Settings>
<Connection>
	 <UserID>sa</UserID>
	 <DataSource>Server</DataSource>
	 <InitialCatalog>Database</InitialCatalog>
</Connection>
</Settings>
To get the Xml text is:
VB.NET:
Dim m_xmld As XmlDocument
	Dim m_nodelist As XmlNodeList
	Dim m_node As XmlNode
 
	m_xmld = New XmlDocument()
 
	m_xmld.Load("Settings.xml")
 
	m_nodelist = m_xmld.SelectNodes("/Settings/Connection")
 
	For Each m_node In m_nodelist
	 Dim UserID = m_node.ChildNodes.Item(0).InnerText
	 Dim DataSource = m_node.ChildNodes.Item(1).InnerText
	 Dim InitialCatalog = m_node.ChildNodes.Item(2).InnerText
	Next
How about if i add in one time tag...
VB.NET:
<Settings>
<Connection>
	  <UserID>sa</UserID>
	  <DataSource>Server</DataSource>
	  <InitialCatalog>Database</InitialCatalog>
		  <Register>
			 <Time hour="23" min=40">
			 <Date>22/10/78</Date>
		  </Register>
</Connection>
<Connection>
	  <UserID>sa</UserID>
	  <DataSource>Server</DataSource>
	  <InitialCatalog>Database</InitialCatalog>
		  <Register>
			 <Time hour="23" min=40">
			 <Date>22/10/78</Date>
		  </Register>
</Connection>
</Settings>
How do i use the above node.ChildNodes method to get the "23" or "40" out from the Xml tag....

I need to loop through all the nodes...and I am using XmlDocument...

Any suggestion or link will be appreciated...

Thanks
 
Last edited:
Top Bottom