how to strip namespaces with e4x?
I have an arbitrary XML document provided by a URL. I also have an xpath-like expre开发者_开发技巧ssions.
var xml = <doc><node1><node2><node3>some value</node3></node2></node1></doc>;
var path = "node1.node2.node3";
I need to verify if the above path into the XML is valid. I tried to do this using eval and E4X.
var value = eval("xml."+path);
However, my actual xml document has namespaces which are getting in the way. I do not know the namespaces ahead of time or care what they are.
Is there a way to strip all the namespaces out ahead of time? Is there a better way to do this?
Thanks!
In E4X you can use a wildcard for namespace prefixes. So if you transform node1.node2.node3
into *::node1.*::node2.*::node3
your eval
will match, ignoring namespaces.
精彩评论