XPath not working with xmlns attribute
-
I have an xml file and I am trying to use selectnodes with an xpath expression which is not working. After trial and error I found that the xml file has this rootnode <batchRequest onError="exit" xmlns="urn:oasis:names:tc:DSML:2:0:core"> and it is getting thrown off with the attribute xmlns. If I remove the xmlns attribute the xpath works fine. The xml file is a DSML message that I am receiving from another application. Is this a bug or some limitation of the xpath? Does xpath has any limitations when it sees an xmlns attribute? Can any one suggest a workaround with this problem.
-
I have an xml file and I am trying to use selectnodes with an xpath expression which is not working. After trial and error I found that the xml file has this rootnode <batchRequest onError="exit" xmlns="urn:oasis:names:tc:DSML:2:0:core"> and it is getting thrown off with the attribute xmlns. If I remove the xmlns attribute the xpath works fine. The xml file is a DSML message that I am receiving from another application. Is this a bug or some limitation of the xpath? Does xpath has any limitations when it sees an xmlns attribute? Can any one suggest a workaround with this problem.
-
I have an xml file and I am trying to use selectnodes with an xpath expression which is not working. After trial and error I found that the xml file has this rootnode <batchRequest onError="exit" xmlns="urn:oasis:names:tc:DSML:2:0:core"> and it is getting thrown off with the attribute xmlns. If I remove the xmlns attribute the xpath works fine. The xml file is a DSML message that I am receiving from another application. Is this a bug or some limitation of the xpath? Does xpath has any limitations when it sees an xmlns attribute? Can any one suggest a workaround with this problem.
you have to use a namespacemanager. xmlns stands for XML Namespace. Once you add the value to the namespacemanager then you can use xpath.
dim namespaceManager as XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDocument.NameTable) namespaceManager.AddNamespace("oasis", "urn:oasis:names:tc:DSML:2:0:core")
Then when you use xPath, you have to use your custom namespacemanager, and everything should work fine. Jason
-
you have to use a namespacemanager. xmlns stands for XML Namespace. Once you add the value to the namespacemanager then you can use xpath.
dim namespaceManager as XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDocument.NameTable) namespaceManager.AddNamespace("oasis", "urn:oasis:names:tc:DSML:2:0:core")
Then when you use xPath, you have to use your custom namespacemanager, and everything should work fine. Jason