Skip to content

Instantly share code, notes, and snippets.

@statique
Created September 5, 2012 04:14
Show Gist options
  • Save statique/3630294 to your computer and use it in GitHub Desktop.
Save statique/3630294 to your computer and use it in GitHub Desktop.
Demonstrates Nori's improper conversion of attribute-less elements
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
@statique
Copy link
Author

statique commented Sep 5, 2012

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

@chrisgibson
Copy link

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