-
Notifications
You must be signed in to change notification settings - Fork 19
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
json output #29
Comments
Because nobody has contributed that feature yet! But also there are issues with translating XML to JSON, because JSON does not have a direct corollary to element attributes. Saxerator gets around this by using extended classes for String and Hash which have I'm open to proposals! |
similarly, I'm looking for a flat :string output so I can parse the result in my own classes! |
Proposal: Use XML: <products>
<product>
<name>iPhone</name>
<price currency="USD">1337</price>
</product>
</products> OUTPUT: parser.for_tag('product').each do |item|
p item # => { 'name' => 'iPhone', 'price' => 1337, 'price@currency' => 'USD' }
end |
@v3rmin With this flow ti'll require to parse attribute names and it'd hard to understand that this it actually relate to the same node.
Also we're talking about JSON it should be a String, not a Hash. |
I think it must be a markup that doesn't collide with valid XML. xml = <<-XML
<product>
<name>iPhone</name>
<price currency="USD">
<value>1337</value>
<attributes>
<currency>EUR</currency>
</attributes>
</price>
</product>
XML
require 'saxerator'
parser = Saxerator.parser(xml)
parser.for_tag('product').each do |item|
p item # => {"name"=>"iPhone", "price"=>{"value"=>"1337", "attributes"=>{"currency"=>"EUR"}}}
end |
Just wondering why saxerator doesn't feature a :json output option?
The text was updated successfully, but these errors were encountered: