XPath problem
-
Hi, I have a problem parsing a WSDL xml with an XMlDocument. This is a short version of the XML: The code I use is: Dim dom As New System.Xml.XmlDocument dom.Load(URL.Text) 'Create an XmlNamespaceManager for resolving namespaces. Dim nsmgr As System.Xml.XmlNamespaceManager = _ New System.Xml.XmlNamespaceManager(dom.NameTable) For Each att As System.Xml.XmlAttribute In dom.DocumentElement.Attributes If att.Prefix = "xmlns" Then nsmgr.AddNamespace(att.LocalName, att.Value) End If If att.LocalName = "xmlns" Then nsmgr.AddNamespace("", att.Value) End If Next When I use the commandwindow for selecting the service element I get: >? dom.selectsinglenode("./node()[1]/service",nsmgr) Nothing But the statement below gives >? dom.selectsinglenode("./node()[1]/node()[8]",nsmgr) {System.Xml.XmlElement} [System.Xml.XmlElement]: {System.Xml.XmlElement} Attributes: {System.Xml.XmlAttributeCollection} BaseURI: "http://localhost/webreferenceaddin.defaultcustomer/customerengine.asmx?wsdl" ChildNodes: {System.Xml.XmlChildNodes} FirstChild: {System.Xml.XmlElement} HasChildNodes: True InnerText: "" InnerXml: "
-
Hi, I have a problem parsing a WSDL xml with an XMlDocument. This is a short version of the XML: The code I use is: Dim dom As New System.Xml.XmlDocument dom.Load(URL.Text) 'Create an XmlNamespaceManager for resolving namespaces. Dim nsmgr As System.Xml.XmlNamespaceManager = _ New System.Xml.XmlNamespaceManager(dom.NameTable) For Each att As System.Xml.XmlAttribute In dom.DocumentElement.Attributes If att.Prefix = "xmlns" Then nsmgr.AddNamespace(att.LocalName, att.Value) End If If att.LocalName = "xmlns" Then nsmgr.AddNamespace("", att.Value) End If Next When I use the commandwindow for selecting the service element I get: >? dom.selectsinglenode("./node()[1]/service",nsmgr) Nothing But the statement below gives >? dom.selectsinglenode("./node()[1]/node()[8]",nsmgr) {System.Xml.XmlElement} [System.Xml.XmlElement]: {System.Xml.XmlElement} Attributes: {System.Xml.XmlAttributeCollection} BaseURI: "http://localhost/webreferenceaddin.defaultcustomer/customerengine.asmx?wsdl" ChildNodes: {System.Xml.XmlChildNodes} FirstChild: {System.Xml.XmlElement} HasChildNodes: True InnerText: "" InnerXml: "
Hi Raf! You could use following XPath query: node()[1]/*[name()='service'] For a good overview of all XPath possiblities (including interactive testing!), visit http://www.zvon.org/xxl/XPathTutorial/General/examples.html. To do some more interactive testing you can use the XPath Visualizer Version 1.4 (http://www.vbxml.com/xpathvisualizer/default.asp). Greetz Jan
-
Hi Raf! You could use following XPath query: node()[1]/*[name()='service'] For a good overview of all XPath possiblities (including interactive testing!), visit http://www.zvon.org/xxl/XPathTutorial/General/examples.html. To do some more interactive testing you can use the XPath Visualizer Version 1.4 (http://www.vbxml.com/xpathvisualizer/default.asp). Greetz Jan
Thank you for the solution. It works. I will check the site later this week. Raf.