Nokogiri XML 生成器换行符

发布于 2024-11-17 17:06:00 字数 468 浏览 1 评论 0原文

Nokogiri XML Builder 正在向输出的 XML 中随机添加新行。

如何让 Nokogiri 在每个标签后输出一个新行。

例如,我得到的输出是

<books>
   <book>
      <title>foobar</title><author>Me
      </author>
   <book>
</books>

,但我想要

<books>
   <book>
      <title>foobar</title>
      <author>Me</author>
   <book>
</books>

什么是错的!!!!!!???

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>
</books>

but i want

<books>
   <book>
      <title>foobar</title>
      <author>Me</author>
   <book>
</books>

WHAT IS WRONG!!!!???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜声 2024-11-24 17:06:00

问题出在您的代码中,但是,因为您说“不,我不能。我只需要一个解释”。我们无法帮助您修复它。

这会生成您想要的输出。您需要弄清楚如何使其适用于您的情况:

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>

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>
琴流音 2024-11-24 17:06:00

这是 Nokogiri 的 jRuby 版本的一个错误。我已经确认它存在于 jRuby 1.6.3 和 1.5.0.beta.2 上

尝试更新到最新版本,看看是否可以解决问题,如果没有,您可能只需要等待或处理它与此同时。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文