views:

72

answers:

1

I have an arbitrary XML document provided by a URL. I also have an xpath-like expressions.

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!

+1  A: 

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.

Dave Ray