所以从一个特定的行开始,它似乎在它下面的行中引起错误,抱歉这个问题看起来很模糊,我无法清楚地说明我在这一行上做得很好。
builder = Nokogiri::XML::Builder.new do |xml|
xml.send('document-id' => '{some-fake-id}', 'type' => 'documentType', 'iso-code' => 'BP', 'training' => 'false', 'send-type' => 'ctype', 'exempt' => 'false', 'cout' => 'false', 'void' => 'false', 'void-stored' => 'false', 'auto' => 'false', 'detail' => 'false', 'regular' => 'true', 'close' => 'false', 'vo' => 'false', 'mod' => 'false')
{
xml.send(:"t-id", $ID)
xml.send(:"v-id", "0")
xml.date $todayis.to_s
xml.send(:"time"('dts' => "+05:00", today.year + "-" + today.month + "-2009:37:55.000+01:00"))
xml.send(:"b-date", $todayis)
xml.send(:"ticket-open-time", ('dts' => "+01:00")_ today.year + "-" + today.month + "-20T09:37:55.000+01:00")
等
发生的错误是:
syntax error, unexpected '\n', expecting =>
答案 0 :(得分:0)
要获得<time dst="+05:00">2014-05-2009:38:48.946+01:00</time>
格式化字符串,您应该使用以下nokogiri调用:
xml.send :"time" , :"dts" => "+05:00" do |xml|
xml << today.year + "-" + today.month + "-2009:37:55.000+01:00"
end
简而言之,nokogiri使用如下语法:
xml.send :"tag", :key1=>"value1", :key2=>"value2" do |var|
var.nestedtag
var<<"content"
end
呈现给:
<tag key1="value1" key2="value2"><nestedtag /> content </tag>
查看docs和来源获取更多信息(确实)。
因此,您的生成器可能看起来像这样(我已经引用了您的变量以获得可读性):
builder = Nokogiri::XML::Builder.new do |xml|
xml.root :"document-id" => '{some-fake-id}',
:"type" => 'documentType',
:"iso-code" => 'BP',
:"training" => 'false',
:"send-type" => 'ctype',
:"exempt" => 'false',
:"cout" => 'false',
:"void" => 'false',
:"void-stored" => 'false',
:"auto" => 'false',
:"detail" => 'false',
:"regular" => 'true',
:"close" => 'false',
:"vo" => 'false',
:"mod" => 'false' do |xml|
xml.send :"t-id", "$ID"
xml.send :"v-id", "0"
xml.date "$todayis".to_s
xml.send :"time" , :"dts" => "+05:00" do |xml|
xml << "today.year" + "-" + "today.month" + "-2009:37:55.000+01:00"
end
xml.send :"b-date", "$todayis"
xml.send :"time" , :"dts" => "+05:00" do |xml|
xml << "today.year" + "-" + "today.month" + "-2009:37:55.000+01:00"
end
xml.send :"ticket-open-time", :'dts' => "+01:00" do |xml|
xml << "today.year" + "-" + "today.month" + "-20T09:37:55.000+01:00"
end
end
将呈现给:
<?xml version="1.0"?>
<root document-id="{some-fake-id}" type="documentType" iso-code="BP" training="false" send-type="ctype" exempt="false" cout="false" void="false" void-stored="false" auto="false" detail="false" regular="true" close="false" vo="false" mod="false">
<t-id>$ID</t-id>
<v-id>0</v-id>
<date>$todayis</date>
<time dts="+05:00">today.year-today.month-2009:37:55.000+01:00</time>
<b-date>$todayis</b-date>
<time dts="+05:00">today.year-today.month-2009:37:55.000+01:00</time>
<ticket-open-time dts="+01:00">today.year-today.month-20T09:37:55.000+01:00</ticket-open-time>
</root>