要获得
<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>