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

Greg

use namespace
http://social.msdn.microsoft.com/Forums/is/xmlandnetfx/thread/5ae834d2-59ed-44d6-b6da-0a7bf5795caa

your problem is namespace

when the namespace is define
all will good

http://www.xml.com/pub/a/2000/07/12/vbasic/vb_and_xml.html?page=1

http://www.codeproject.com/KB/cpp/parsefilecode.aspx

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
      myxmldoc.setProperty("SelectionNamespaces","xmlns:xyz='http://url.com/xyz'")

      mynodelist = myxmldoc.SelectNodes(XPath to specific node?)
      For Each m_node In mynodelist
      'see link
      Next

Thanks, I think this will get me there. I found some other examples using XmlNamespaceManager.

Greg

This article has been dead for over six months. Start a new discussion instead.