maik / xml-simple

Easy API for working with XML documents
MIT License
88 stars 27 forks source link

Inconsistent behaviour when 'content' key contains an array #12

Closed 907th closed 10 years ago

907th commented 10 years ago

The issue:

XmlSimple.xml_in '<a>1<b>3</b>5</a>' 
# => {"b"=>["3"], "content"=>["1", "5"]}
XmlSimple.xml_out XmlSimple.xml_in '<a>1<b>3</b>5</a>' 
# => "<opt>[&quot;1&quot;, &quot;5&quot;]<b>3</b>\n</opt>\n"

or simply:

XmlSimple.xml_out({a: [{ 'content' => ['123'] }]})
# => "<opt>\n  <a>[&quot;123&quot;]</a>\n</opt>\n"

but all is ok when content key contains a string:

XmlSimple.xml_out({a: [{ 'content' => '123' }]})
# => "<opt>\n  <a>123</a>\n</opt>\n"

PS: Thanks for the library, it is awesome!

maik commented 10 years ago

Hi Alexey!

Thank you for using XmlSimple and thank you for reporting this issue! I'll have a look at it!

Have a nice weekend!

Maik

On Thu, Aug 7, 2014 at 8:19 AM, Alexey Chernenkov notifications@github.com wrote:

The issue:

XmlSimple.xml_in '135' # => {"b"=>["3"], "content"=>["1", "5"]}XmlSimple.xml_out XmlSimple.xml_in '135' # => "["1", "5"]3\n\n"

or simply:

XmlSimple.xml_out({a: [{ 'content' => ['123'] }]})# => "\n ["123"]\n\n"

but all is ok when content key contains a string:

XmlSimple.xml_out({a: [{ 'content' => '123' }]})# => "\n 123\n\n"

PS: Thanks for the library, it is awesome!

— Reply to this email directly or view it on GitHub https://github.com/maik/xml-simple/issues/12.

Start simple or fail!

I am a software developer, hardware enthusiast, and a writer:

Follow me on Twitter: @maik_schmidt

907th commented 10 years ago

As docs says:

Mixed content (elements which contain both text content and nested elements) will be not be represented in a useful way - element order and significant whitespace will be lost. If you need to work with mixed content, then XmlSimple is not the right tool for your job - check out the next section.

So I close the issue.