Skip to content
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

return an empty node set when xpath expression doesn't match #8

Merged
merged 1 commit into from
Jan 18, 2017
Merged

return an empty node set when xpath expression doesn't match #8

merged 1 commit into from
Jan 18, 2017

Conversation

clarkevans
Copy link
Contributor

No description provided.

@bicycle1885
Copy link
Member

Could you show me any examples that will cause a problem?

@bicycle1885
Copy link
Member

For example, the following example does not fail even though there is no matching nodes for a query:

julia> doc = parsexml("""<root/>""")
EzXML.Document(EzXML.Node(<DOCUMENT_NODE@0x00007fc53d7e9b10>))

julia> find(doc, "//notexit")
0-element Array{EzXML.Node,1}

@clarkevans
Copy link
Contributor Author

clarkevans commented Jan 17, 2017

This seems to be a minimal test case where it fails (extracted from a huge input and messy xpath query)

using EzXML
doc = parsexml("""<root xmlns="urn:foo"/>""")
rs = find(root(doc), "//foo:notexit/*", [("foo", "urn:foo")])

Perhaps it is triggering some deep bug in libxml (v2.9.3) causing the null pointer, alas, this case happens everywhere in my data sets and I've been unable to write an xpath expression that avoids the issue.

BTW, thank you for the lovely EzXML library. It's very much appreciated.

@bicycle1885
Copy link
Member

Thank you. I've quickly checked libxml2 and found the following macro in xpath.h:

/**
 * xmlXPathNodeSetIsEmpty:
 * @ns: a node-set
 *
 * Checks whether @ns is empty or not.
 *
 * Returns %TRUE if @ns is an empty node-set.
 */
#define xmlXPathNodeSetIsEmpty(ns)                                      \
    (((ns) == NULL) || ((ns)->nodeNr == 0) || ((ns)->nodeTab == NULL))

So, your patch looks good to me 👍 .

@bicycle1885 bicycle1885 merged commit 77cbcfd into JuliaIO:master Jan 18, 2017
bicycle1885 added a commit that referenced this pull request Jan 18, 2017
@bicycle1885 bicycle1885 mentioned this pull request Jan 18, 2017
bicycle1885 added a commit that referenced this pull request Jan 19, 2017
@Osirisxblack
Copy link

👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants