-
Notifications
You must be signed in to change notification settings - Fork 332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nodesForXPath fails if xml document has DOCTYPE #20
Comments
Thanks for the fixes, I was getting mad at this. However, there is still a major problem with default namespaces. In other words, if you add a default namespace on the root node, as in:
then test 4 fails, both with your fix and without. Presumably, all other tests after test 4 should also fail. This is really annoying. According to this post http://www.perlmonks.org/?node_id=530519 the behaviour of KissXML seems to actually be the correct one, while NSXML is wrong. The problem boils down to the fact that, according to post above, "/menu/pizza" shall match both "menu" and "pizza" in the null namespace, not in the default one. However, since:
I hope this could be fixed somehow. Waiting for a better fix, I am now using this one instead of yours:
with this, at least there's a way to match elements in the default namespace (for example you can write "/restaurant:menu/restaurant:pizza" instead of "/menu/pizza"). Ugly, but better than nothing. |
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 robbiehanson#19, the second half of issue robbiehanson#20.
The existing code uses doc->children, which is wrong in the case that the document has a doctype or PI nodes at the start. This fix is originally from upstream issue robbiehanson#20, by kgrigsby59. This changeset re-applies the fix on top of the nodesforxpath-namespacemappings branch (the two changes are in the same area of code).
If you add a DOCTYPE to the xml in testNodesForXPath you'll see that test 6 fails. For instance I added the following.
It fails because in DDXMLNode nodesForXPath:error: because the line
returns the a node with the name AirSync instead of the real root node. I changed this to
Also if the xml uses a default namespace such as
and you try to add a prefixed namespace to the root node such as
it will fail. This is because a non-prefixed namespace is added in the line
I changed this to
and now it works. In summary I changed
to
The text was updated successfully, but these errors were encountered: