VB.NET: Simple XML problem

toytoy

Well-known member
Joined
Jul 16, 2004
Messages
46
Programming Experience
1-3
Say i have these XML tag:
VB.NET:
<Books country = "USA" date= "21/1/2005"> 
	  <Title section ="1"> 
		  <Reference web = "[url="http://www.any.com"]www.any.com[/url]" topic = "1"> 
	  </Title> 
	  <Title section ="1"> 
		  <Reference web = "[url="http://www.idea.com"]www.idea.com[/url]" topic = "2"> 
	  </Title> 
	  <Title section ="2"> 
		  <Reference web = "[url="http://www.howTo.com"]www.howTo.com[/url]" topic = "3"> 
	  </Title> 
	  <Title section ="3"> 
		  <Reference web = "[url="http://www.do.com"]www.do.com[/url]" topic = "4"> 
	  </Title> 
</Books>
how do i actually extract the country and date attributes using XMLDocument


I tried but it could not worked, below is my coding
VB.NET:
Dim cou, da As Integer
Dim xdoc As New XmlDocument
Dim nodelist As XmlNodeList
Dim node As XmlNode

xdoc.Load("..\book.xml")

nodelist = xdoc.SelectNodes("/Books")

For Each node In nodelist
  cou = node.Attributes.GetNamedItem("country").Value
  MessageBox.Show(cou)
  da = node.Attributes.GetNamedItem("date").Value
  MessageBox.Show(da)
Next
and substring the "1" from the date attributes........

Thanks
 
Try this:

change : nodelist = xdoc.SelectNodes("/Books")
to : nodelist = xdoc.GetElementsByTagName("Books")

and : cou = node.Attributes.GetNamedItem("country").Value
To : cou = node.Attributes("country").innertext

I don't have time to check it so no guarantee.. :)

TPM
 
Back
Top