Nokogiri XML Builder is randomly adding new lines to the outputted XML.
How can I get Nokogiri to output a new line after each tag.
For example, the output I am getting is
<books>
<book>
<title>foobar</title><author>Me
</author>
<book>
</bo开发者_如何学JAVAoks>
but i want
<books>
<book>
<title>foobar</title>
<author>Me</author>
<book>
</books>
WHAT IS WRONG!!!!???
The problem is in your code, but, because you said "No, I can't. I just need an explanation." we can't help you fix it.
This generates the output you want. You'll need to figure out how to make it apply to your situation:
require 'nokogiri'
builder = Nokogiri::XML::Builder.new do |xml|
xml.books {
xml.book {
xml.title { xml.text 'foobar' }
xml.author { xml.text 'Me' }
}
}
end
puts builder.to_xml
# >> <?xml version="1.0"?>
# >> <books>
# >> <book>
# >> <title>foobar</title>
# >> <author>Me</author>
# >> </book>
# >> </books>
This is a bug with the jRuby version of Nokogiri. I've confirmed it as being present on jRuby 1.6.3 with 1.5.0.beta.2
Try updating to the latest version to see if that resolves the problem, if not you'll likely just have to wait or deal with it in the meantime.
精彩评论