how to use xpath to get xml nodes(the xml includes namespace) #19

sakura0720 opened this Issue Jul 26, 2012 · 0 comments


None yet
1 participant

When I use xpath to get xml nodes as below, it returns 0 objects. I know the reason is xml's namespace. But I don't know how to solve this problem with KissXML.

ps: I use "[]" to replace "<>" because of the github editor can't display them rightly.

[?xml version="1.0" encoding="utf-8"?]
[soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap=""]
[HelloTestResponse xmlns=""]

KissXML method:
DDXMLDocument *doc = [[DDXMLDocument alloc] initWithXMLString:theXML options:0 error:nil];
NSArray *nodes = [doc nodesForXPath:@"//HelloTestResponse" error:nil];

The nodes' count is always 0;

ewanmellor added a commit to tipbit/KissXML that referenced this issue Apr 28, 2013

Implement DDXMLNode nodesForXPath:namespaceMappings:error.
This allows the caller to pass in an NSDictionary specifying the mapping
from namespace prefix to namespace URL.  Namespace prefixes specified in
the given XPath will then be resolved against that mapping.

This allows callers to find nodes using default namespaces, e.g.
<element xmlns='<schema URL>'>...</element>.  The caller must specify
prefix=<schema URL> in namespaceMappings, and then can use prefix:element
in the XPath.

If namespaceMappings is nil, then the existing behavior is used
(parsing the namespaces from the document node).  This works in the
situation where the namespaces are all named explicitly, and all on the
root node, but not in general.

This addresses upstream issue #19, the second half of issue #20.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment