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

XML: improve xpath regarding namespaces #9288

Merged
merged 2 commits into from
May 14, 2020
Merged

Conversation

asterite
Copy link
Member

Fixes #9279

I checked Nokogiri and if you do this:

require "nokogiri"

str_xml = <<-XML
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
  <soap:Body>
    <NumberToWordsResponse xmlns="http://www.dataaccess.com/webservicesserver/">
      <NumberToWordsResult>string</NumberToWordsResult>
    </NumberToWordsResponse>
  </soap:Body>
</soap:Envelope>
XML

xml = Nokogiri::XML(str_xml)
xml.xpath("/soap:Envelope/soap:Body")

It works out of the box. My guess is that it passes the root namespaces of the document so they can be found with the registered prefixes. So in this PR I do the same.

I also lchop the "xmlns:" prefix of namespaces when registering them. Again, checking what Nokogiri does, the namespaces are returned with the "xmlns:" prefix, but that needs to be removed when registering namespaces for the xpath lookup.

@asterite asterite added kind:bug A bug in the code. Does not apply to documentation, specs, etc. kind:feature topic:stdlib:serialization labels May 13, 2020
src/xml/xpath_context.cr Outdated Show resolved Hide resolved
@asterite asterite added this to the 0.35.0 milestone May 14, 2020
@asterite asterite merged commit 6d0d63f into master May 14, 2020
@asterite asterite deleted the feature/xml_path_namespaces branch May 14, 2020 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. kind:feature topic:stdlib:serialization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

XML::Node.xpath_node dose not accept XML::Namespace
4 participants