You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unfortunately, this is not how namespaces work. Just because your <root/> element uses a default namespace, this doesn't mean that there is automatically a binding for a default namespace in your XPath expression. For example:
// But this failsassertEquals("baz", $(xml).xpath("//root/bar").content());
This can't work because you're querying "unnamespaced" root and bar elements. Imagine the default namespace was set on the bar element, rather than the root element:
<root><barxmlns="http://foo.com">baz</bar></root>
This:
// This fails tooassertEquals("baz", $(xml).namespace("", "http://foo.com").xpath("//root/bar").content());
The correct solution here would be to express the following XPath:
//:root/:bar
The best idea would be to bind explicit namespaces for your XPath:
Note, we also have #102 in our roadmap to simply remove namespaces from documents. Often, this will make queries much more easy without necessarily changing semantics
@breedx2 : You're welcome. No worries, I constantly have to review namespaces myself. The rule of thumb is that once you add namespaces to your document, everything changes drastically
XML documents that have a root xmlns with no prefix cannot be parsed with xpath.
Here is a unit test that produces this problem:
It should be possible to use xpath on documents with a root xmlns declaration with no prefix, but it just doesn't work.
Joox 1.2.0 on OSX.
Originally reported here:
https://code.google.com/p/joox/issues/detail?id=121
The text was updated successfully, but these errors were encountered: