Xml Namespace breaking my xpath!
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']
The List element has been defined with a default namespace and this is adopted by all elements inside.
You therefore need to ignore the element namespace like so:
/*[local-name()='List']/*[local-name()='Fields]/*[local-name()='Field]
but this means that the xpath will pick up any other element with List - Fields - Field
You can do a namespace check as well as a local-name check like so:
/*[local-name()='List' and namespace-uri()='http://schemas.microsoft.com/sharepoint/soap/']/*[local-name()='Fields' and namespace-uri()='http://schemas.microsoft.com/sharepoint/soap/']/*[local-name()='Field' and namespace-uri()='http://schemas.microsoft.com/sharepoint/soap/']
Or you can register the namespace with the library and then explicitly specify the prefix for that namespace and add it to xpath expression, the method of which is dependent on the library you are using.