gpt4 book ai didi

ruby - 如何让 Nokogiri 添加正确的 XML 编码?

转载 作者:数据小太阳 更新时间:2023-10-29 01:39:10 25 4
gpt4 key购买 nike

我用 Nokogiri 创建了一个 xml 文档:Nokogiri::XML::Document

我文件的标题是<?xml version="1.0"?>但我希望有 <?xml version="1.0" encoding="UTF-8"?> .我可以使用任何选项来显示编码吗?

最佳答案

你在使用 Nokogiri XML Builder ?您可以将编码选项传递给 new() 方法:

new(options = {})

Create a new Builder object. options are sent to the top level Document that is being built.

Building a document with a particular encoding for example:

  Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
...
end

还有 this page表示您可以执行以下操作(不使用 Builder 时):

doc = Nokogiri.XML('<foo><bar /><foo>', nil, 'EUC-JP')

大概您可以将“EUC-JP”更改为“UTF-8”。

关于ruby - 如何让 Nokogiri 添加正确的 XML 编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4381710/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com