I have an XML file (see attached) that has numerous different sections/categories.
What I'm looking for is advice on how to pick out the different levels/categories and display them one after the other, with the click of a button obviously. Much like you would/can with a recordset using ADO.
There are a number of ways that you can go about doing this.
For instance you can use the .SelectSingleNode and .SelectNodes , methods on the XmlDocument class, which take as an input an XPath query. If you search the forums for either of those methods you will find lots of examples, and you can follow the link in my signature for finding out about XPath.
Another alternative would be to use LINQ. I don't know too much about this, but again, if you search the forum you will find examples of using LINQ with XML.
Just a question though, one of the nodes I'm looking at has quotes (double) in it, around cate and gui (see code below)
Code:
<integer id="cate" value="gui " />
Do I need to include these double quotes in my code or not? Below is my vb code but it produces an error '//integer id="cate" value="gui "' has an invalid token', any ideas why, and what does it mean?
Code:
Dim nod As XmlNode = xd.SelectSingleNode("//integer id=""cate"" value=""gui """)
What you are describing are the attributes on the XML Node, and using XPath, they are accessed in a different way, i.e the XPath query that you would need, would be something like:
Would that method return all attribute matching the xpath query, or just the first one?
If it is just the first one what method do i need to use to return all matching attributes? And also how do i perform a loop in the xml to count all matching attributes?
Another thing, what about the value="gui " part of the query? would i just add & value[@id="gui " to your example, ie.
If you haven't done so already, download the XpathBuilder from the link in my signature, it makes answering that question very easy
Rather than & you would use "and" as in:
/properties/list/record/integer[@id="cate" and @id="gui"]
This XPath doesn't work in XPathBuilder, I can't remember the reason why is doesn't but as per the XPath Standard it should work, so give it a try in your code.