Nokogiri to_xml without carriage returns

前端 未结 3 945
再見小時候
再見小時候 2020-12-30 02:04

I\'m currently using the Nokogiri::XML::Builder class to construct an XML document, then calling .to_xml on it. The resulting string always contains a bunch of spaces, line

3条回答
  •  [愿得一人]
    2020-12-30 02:24

    b.to_xml returns a string. You just need to replace the first instance of \n in the string.

    require 'nokogiri'
    
    b = Nokogiri::XML::Builder.new do |xml|
      xml.root do
        xml.text("Value")
      end
    end
    
    b.to_xml.sub("\n",'')
    

    Probably easier than trying to overload the method.

提交回复
热议问题