G
Guest
Hi,
I'm trying to read an XML file using VB.NET and I can't get the XPath
queries to work. Here's a snippet of the XML file I'm using and the code:
<?xml version="1.0" encoding="UTF-8"?>
<job xmlns="http://ns.real.com/tools/job.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ns.real.com/tools/job.2.0
http://ns.real.com/tools/job.2.0.xsd">
<clipInfo>
<entry>
<name>Author</name>
<value type="string">This is the author</value>
</entry>
Dim doc As New XmlDocument, root As XmlElement, entryList As
XmlNodeList
doc.Load("job.xml")
Dim nsmgr As New XmlNamespaceManager(doc.NameTable)
nsmgr.AddNamespace(String.Empty, "http://ns.real.com/tools/job.2.0")
nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")
root = doc.DocumentElement
entryList = root.SelectNodes("/job/clipInfo/entry")
For Each x As XmlNode In entryList
MsgBox(x.InnerXml)
Next
When I run this zero nodes are returned. I think it has something to do with
the namespaces but I don't know how to fix it (I tried reading the document
without using an XMLNameSpaceManager and it still didn't work). Any help
would be greatly appreciated!
I'm trying to read an XML file using VB.NET and I can't get the XPath
queries to work. Here's a snippet of the XML file I'm using and the code:
<?xml version="1.0" encoding="UTF-8"?>
<job xmlns="http://ns.real.com/tools/job.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ns.real.com/tools/job.2.0
http://ns.real.com/tools/job.2.0.xsd">
<clipInfo>
<entry>
<name>Author</name>
<value type="string">This is the author</value>
</entry>
Dim doc As New XmlDocument, root As XmlElement, entryList As
XmlNodeList
doc.Load("job.xml")
Dim nsmgr As New XmlNamespaceManager(doc.NameTable)
nsmgr.AddNamespace(String.Empty, "http://ns.real.com/tools/job.2.0")
nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")
root = doc.DocumentElement
entryList = root.SelectNodes("/job/clipInfo/entry")
For Each x As XmlNode In entryList
MsgBox(x.InnerXml)
Next
When I run this zero nodes are returned. I think it has something to do with
the namespaces but I don't know how to fix it (I tried reading the document
without using an XMLNameSpaceManager and it still didn't work). Any help
would be greatly appreciated!