XPath navigation with namespaces
-
I have a program that uses xpath expressions to navigate an XPathDocument, e.g.
dim iter as XPathNodeIterator = myNav.Select(myXpathExpression)
Today, to make the XML source document easier to edit, I added a target namespace, i.e.
<MyDocElement xmlns="http://x.y.com/abc/Mapping.xsd">
. After I did this, my xpath expressions no longer work. Does anyone know what I need to do to make them work again? (Note that I am not using a namespace prefix).
-
I have a program that uses xpath expressions to navigate an XPathDocument, e.g.
dim iter as XPathNodeIterator = myNav.Select(myXpathExpression)
Today, to make the XML source document easier to edit, I added a target namespace, i.e.
<MyDocElement xmlns="http://x.y.com/abc/Mapping.xsd">
. After I did this, my xpath expressions no longer work. Does anyone know what I need to do to make them work again? (Note that I am not using a namespace prefix).
hi, I can remember I had similar problem long time ago... I can't recall how I solved that one, bt why are you not using namespace prefix? It should work with it and I see no reason why not to use it... :confused: best regards, David 'DNH' Nohejl Never forget: "Stay kul and happy" (I.A.)
-
hi, I can remember I had similar problem long time ago... I can't recall how I solved that one, bt why are you not using namespace prefix? It should work with it and I see no reason why not to use it... :confused: best regards, David 'DNH' Nohejl Never forget: "Stay kul and happy" (I.A.)
The xml file is large - originally generated, and then hand-modified. I do not want to use namespace prefixes unless I have to, as 1) they will bloat the file 2) it will take a while to edit the file
-
The xml file is large - originally generated, and then hand-modified. I do not want to use namespace prefixes unless I have to, as 1) they will bloat the file 2) it will take a while to edit the file
:doh: oh now I don't even know what I meant :confused: Try to add namespace prefix into XPath query. If it wont work say "DNH is idiot" (cuz i think there is no difference when you have namespace prefix in every element or only in parent) and look at link I provide you now; hopefully the answer will be here[^] I didn't read it all bt it looks promising. Here is quite late night so I'll leave it alone for now. plz if you'll find answer post it here.. In other case I'll look at it tomorrow... good luck, David Never forget: "Stay kul and happy" (I.A.)
-
The xml file is large - originally generated, and then hand-modified. I do not want to use namespace prefixes unless I have to, as 1) they will bloat the file 2) it will take a while to edit the file
I finally found something what seems to be solution... [ snippet is from my website's rss feeder - i *think* it worked...]
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("ns",@"http://www.w3.org/1999/xhtml"); XmlNodeList newsNodes = doc.DocumentElement.SelectNodes("//ns:body/ns:form/ns:div[@class='parent']/ns:div[@class='contents']/ns:div[@class='news']",nsmgr);
David Never forget: "Stay kul and happy" (I.A.) -
I finally found something what seems to be solution... [ snippet is from my website's rss feeder - i *think* it worked...]
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("ns",@"http://www.w3.org/1999/xhtml"); XmlNodeList newsNodes = doc.DocumentElement.SelectNodes("//ns:body/ns:form/ns:div[@class='parent']/ns:div[@class='contents']/ns:div[@class='news']",nsmgr);
David Never forget: "Stay kul and happy" (I.A.)