Created
September 5, 2012 04:14
-
-
Save statique/3630294 to your computer and use it in GitHub Desktop.
Demonstrates Nori's improper conversion of attribute-less elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'awesome_print' | |
require 'nori' | |
Nori.parser = :nokogiri | |
xml = <<EOS | |
<?xml version="1.0" encoding="UTF-8"?> | |
<categories> | |
<category id="1234"> | |
<styleId>123</styleId> | |
<styleId>456</styleId> | |
<styleId>789</styleId> | |
</category> | |
</categories> | |
EOS | |
hashed = Nori.parse(xml) | |
ap hashed | |
=begin | |
# outputs => | |
{ | |
"categories" => { | |
"category" => { | |
"styleId" => [ | |
[0] #<Nori::StringWithAttributes:0x10094e778 | |
attr_accessor :attributes = {} | |
>, | |
[1] #<Nori::StringWithAttributes:0x10094e228 | |
attr_accessor :attributes = {} | |
>, | |
[2] #<Nori::StringWithAttributes:0x10094db48 | |
attr_accessor :attributes = {} | |
> | |
], | |
"@id" => "1234" | |
} | |
} | |
} | |
=end |
This may be a awesome_print getting in the way (and printing the class name). You should be able to use instances of Nori::StringWithAttributes as a regular Ruby string. If you puts hashed
instead, does it look correct?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If Nori parsed the syle_id correctly in this file, the style id hash would be :style_id => {'123', '456', '789'} instead of #<Nori::StringWithAttributes:0x100xxxxxx