Closed zekefast closed 6 years ago
@zekefast Better ask on StackOverflow
If I remember correctly, it's hard for the elements defined in the class to shake the namespace that was given to them. It's most likely a bug. So you can get around that by creating another class for the element.
require "happymapper"
class PublisherUrl
include ::HappyMapper
content :url, String
end
class AppMapper
include ::HappyMapper
namespace "a"
tag "feed"
element :updated, DateTime
element :title, String
element :id, String
element :description, String, tag: "content"
# element :publisher_url, String, tag: "publisherUrl", namespace: nil
def publisher_url
publisher_url_object.url
end
element :publisher_url_object, PublisherUrl, tag: "publisherUrl"
end
app = AppMapper.parse(File.read('buggy.xml'))
puts "Publisher #{app.publisher_url}"
Oh yeah, here is the issue: https://github.com/mvz/happymapper/issues/43
I have follow XML:
All elements with namespace
a
parsed as expected with follow definition:But
publisher_url
field wasn't parsed.I tried different combinations of xpath, tag, namespace options, but neither is working. When I load this document to Nokogiri. I was able to access element with follow xpath expression:
/a:feed/xmlns:publisherUrl
Versions: ruby: 2.2.1 nokogiri: 1.6.6.2 nokogiri-happymapper: 0.5.9
Does anyone know whether it possible to map such xml using
nokogiri-happymapper
?