I have the following XML:
<List xmlns="http://schemas.microsoft.com/sharepoint/soap/"> <Fields> <Field> </Field> </Fields> </List>
This is a slimmed down version of XML being returned from a SharePoint web service. I also have the following xPath:
/List/Fields/Field
When I remove the xmlns
from my XML the xPath works fine. When it's in there my xPath finds nothing. Is there something I should be doing differently with my xPath? Modifying the XML is not an option.
XPath queries are aware of namespaces in an XML document and can use namespace prefixes to qualify element and attribute names. Qualifying element and attribute names with a namespace prefix limits the nodes returned by an XPath query to only those nodes that belong to a specific namespace.
Name conflicts in XML can easily be avoided using a name prefix. In the example above, there will be no conflict because the two <table> elements have different names.
You can change the default namespace within a particular element by adding an xmlns attribute to the element. Example 4-4 is an XML document that initially sets the default namespace to http://www.w3.org/1999/xhtml for all the XHTML elements.
I also have the following xPath:
/List/Fields/Field
When I remove the xmlns from my XML the xPath works fine. When it's in there my xPath finds nothing
If you cannot register a namespace binding and cannot use (assuming the registered prefix is "x"):
/x:List/x:Fields/x:Field
then there is another way:
/*[name()='List']/*[name()='Fields']/*[name()='Field']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With