I appreciate your response, however it is leading me nowhere. I have
discovered XMLNamespaceManager prior to posting, the docs are not clear how
this resolved my issue.
First, I am not attempting to get to the attributes yet, merely attempting
to count the number of 'middle' nodes in 'top'. So I do not see how I would
change my xpath statement to reflect namespaces.
Second, when I create a document from scratch using these namespaces and
attempt to xpath through the document I am not having any issues. Any ideas
why?
Sample Code to Count Nodes (XML Loaded from File)
Dim objXML As System.Xml.XmlDocument
Dim objNSMGR As Xml.XmlNamespaceManager
objXML = New System.Xml.XmlDocument
objXML.Load(Application.StartupPath & "\xmlfile1.xml")
objNSMGR = New System.Xml.XmlNamespaceManager(objXML.NameTable)
objNSMGR.AddNamespace("firstns", "urn:firstns")
objNSMGR.AddNamespace("secondns", "urn:secondns")
MsgBox(objXML.SelectNodes("top/middle", objNSMGR).Count)
Sample Code to create an query XML
Dim objXML As System.Xml.XmlDocument
Dim objNode As System.Xml.XmlNode
objXML = New System.Xml.XmlDocument
'Create root node
objNode = objXML.CreateNode(Xml.XmlNodeType.Element, "top", "")
'create namespaces
objNode.Attributes.Append(objXML.CreateAttribute(" xmlns"))
objNode.Attributes.GetNamedItem("xmlns").Value = "urn:bob"
objNode.Attributes.Append(objXML.CreateAttribute(" xmlns:firstns"))
objNode.Attributes.GetNamedItem("xmlns:firstns").V alue = "urn:firstns"
objNode.Attributes.Append(objXML.CreateAttribute(" xmlns:secondns"))
objNode.Attributes.GetNamedItem("xmlns:secondns"). Value = "urn:secondns"
'Append root node to #document
objXML.AppendChild(objNode)
'Create first child node
objNode = objXML.CreateNode(Xml.XmlNodeType.Element, "middle", "")
'Create first attribute with namespace-uri
objNode.Attributes.Append(objXML.CreateAttribute(" firstns:name",
"urn:firstns"))
objNode.Attributes.GetNamedItem("firstns:name").Va lue = "test"
'Append node to root node
objXML.SelectSingleNode("top").AppendChild(objNode )
'Count all occurances of middle in top
MsgBox(objXML.SelectNodes("top/middle").Count)
"Bjoern Hoehrmann" <bj****@hoehrmann.dewrote in message
news:la********************************@hive.bjoer n.hoehrmann.de...
>* AMDRIT wrote in microsoft.public.dotnet.xml:
>>I am having an issue with xml and namespaces, at least I think it is
namespaces. When I use namespaces, I cannot use SelectSingleNode /
SelectNodes as they always return 0/Nothing respectively. Anyone have any
thoughts?
You have to declare your namespaces first using e.g. a custom
XmlNamespaceManager or you have to rewrite your expressions to
avoid them like
//foo:bar -//*[local-name() = 'bar' namespace-uri() = '...']
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/