Hi,
what you need is a "namespace manager" to deal with the namespace that is in
your xml doc. If you add the following code:
Dim xreader as XmlTextReader = new XmlTextReader("../config.xml")
Dim xns XmlNamespaceManager = new new XmlNamespaceManager(xreader.NameTable)
xns.AddNamespace("abc", "http://tempuri.org/config1.xsd")
...... and a little modification to your xpath query:
xml_nodelist = xml_doc.SelectNodes("abc:CAREKEEPER",xns)
gets the node successfully.
Note: I sort of hard coded the "abc" and the uri, I think u could write it
in a generic way. Also the xpath is case-sensitive, so be careful while
writing node names in xpath queries.
Second solution:
Just remove the xmlns attribute from the CAREKEEPER node in your xml file
and the code you write should work without the "/" before CAREKEEPER in
xpath query.
I hope this helps.
Ab.
http://joehacker.blogspot.com
"Ian" <Ia*@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
Hi
I'm pretty new at this so please don't laugh too hard. I'm trying to load
an xml document using VB.NET and having a hard time. My code doesn't
crash but it doesn't work either, the first msgbox returns 0.
Help (please!)
Below is my document and snippet of code
<?xml version="1.0" encoding="utf-8"?>
<CAREKEEPER xmlns="http://tempuri.org/config1.xsd">
<TABLEINFORMATION TABLE="workers" ssn="ssn" emplid="userinput1">
</TABLEINFORMATION>
<SERVERS hostname="sta0wp02" database="vividcare">
</SERVERS>
<SERVERS hostname="rdy1cn02" database="vividcare">
</SERVERS>
</CAREKEEPER>
CODE:
Try
xml_doc.Load("../config.xml")
xml_nodelist = xml_doc.SelectNodes("/carekeeper")
MsgBox(xml_nodelist.Count())
For Each xml_node In xml_nodelist
server = xml_node.Item("SERVER").InnerText()
MsgBox(server)
Next
Catch ex As Exception
MsgBox("XMLPARSER: CONFIGURATION FILE ERROR " & ex.Message & "
" & ex.Source)
End Try