NSXML: Using XPath with namespaces?
NSXML: Using XPath with namespaces?
- Subject: NSXML: Using XPath with namespaces?
- From: Jens Alfke <email@hidden>
- Date: Fri, 6 Nov 2009 15:27:09 -0800
I'm calling -[NSXMLElement nodesForXPath:error:] to find stuff in an
XML document. It works great, until I try to find elements that use a
namespace prefix; then it won't find them unless I put the exact same
prefix in the query. That's a bad solution, though, because the prefix
can be arbitrary in different documents; what really counts is the
namespace URI that the prefix is bound to. I can't find a way to query
based on the namespace URI, though.
So for example, if there's a node 'bar' like
<foo xmlns:prefix="http://example.org/some/namespace/URI">
<prefix:bar>content</prefix:bar>
then to find this node in an XPath expression I have to call it
"prefix:bar". But that XPath query wouldn't work on a semantically-
identical document that happens to use a different prefix name, like
<foo xmlns:xiferp="http://example.org/some/namespace/URI">
<xiferp:bar>content</prefix:bar>
To be able to find it there, I'd have to call it "xiferp:bar".
I've looked through the XPath spec and some other stuff I found on the
web, and it looks like the correct solution is to use the namespace-
uri function in the query, sort of like
/bar[namespace-uri()='http://example.org/some/namespace/URI']
but this doesn't work in NSXML; it always returns nil.
Anyone know what the magic incantation is?
—Jens_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden