Closed CoDEmanX closed 9 years ago
The problem has to do with namespaces. The HTML page elements have XHTML namespace and this is the namespace to which evaluator defaults all non-prefixed element selectors to. When you render an XML document with jQuery there is chance these elements now have namespace set to null. So, either you need to supply namespace resolver with the query or change XML embedding mechanism into HTML
I'm loading an XML file via File Reader API (local only), parse it as text, let jQuery turn it into a DOM tree and append it to the page. Then I wanna run xpath queries on this DOM tree.
The problem: an empty object is returned whenever I try to use element names in the xpath expression
Whereas a
*
(to match all immediate children) combined with a predicate filter using the node name worksAm I overlooking something obvious, or is this a bug in jquery-xpath?
It definately considers the dynamically added document nodes when using a predicate filter, so I see no reason why it wouldn't work for a direct XPath.
http://jsfiddle.net/sHz8k/
Example XPath using a predicate filter that works:
//*[name()='sourceFile']
Direct XPath that does not work://sourceFile
Test xml:
Check the console to inspect the object
$.xpath()
returns.