I'm not entirely new to xPath. I've programmed with the TreeView control in VB.Net extensively, so I have a very good grasp of the concept of trees, nodes, parent, children, siblings, etc.
I've read several tutorials on line about using the XmlDocument class in the .Net Framework. All of these examples have very basic XML documents that they parse. It will be something like books and authors or a simple menu. It is very helpful but in the real world the XML documents I work with are always much more complex, most notable on the first few lines.
I can loop through the nodes with an XmlNodeReader but I have trouble with the SelectNodes method of the XmlDocument object.
I realize what follows is not a complete XML document and can't be parsed. This is an example of the first few lines of a file I might get.
<?xml version="1.0" encoding="UTF-8"?> <xyz:Search_Request xmlns:xyz="http://url.com/xyz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <xyz:PayLoad> <xyz:Request> <xyz:Service_data>
What I have trouble with is using the "SelectNodes" method to get the child nodes of a specific node in the document. Looking at the file I can't figure out what the path to "xyz : Service_data" would be. Below is a basic example of the code I am trying to use.
Dim myxmldoc As XmlDocument Dim mynodelist As XmlNodeList Dim mynode As XmlNode myxmldoc = New XmlDocument() myxmldoc.Load("myfile.xml") 'How do I form the path to service_data mynodelist = myxmldoc.SelectNodes(XPath to specific node?) For Each m_node In mynodelist 'parse nodes here Next