0
我需要建立以下XML数据问题在构建XML在轨使用引入nokogiri 4
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:description7a.services.chrome.com">
<soapenv:Header/>
<soapenv:Body>
<urn:VehicleDescriptionRequest>
<urn:accountInfo number="test" secret="test" country="US" language="en" behalfOf="test"/>
<!--You have a CHOICE of the next 3 items at this level-->
<!--Optional:-->
<urn:styleId>test</urn:styleId>
<urn:switch>ShowAvailableEquipment</urn:switch>
<urn:includeMediaGallery>Both</urn:includeMediaGallery>
</urn:VehicleDescriptionRequest>
</soapenv:Body>
</soapenv:Envelope>
我使用下面的代码来构建它
def self.xml_build(style_id,number,secret,behalfOf)
builder = Nokogiri::XML::Builder.new do |xml|
xml.send("soapenv:Envelope"){
xml.send("soapenv:Header")
xml.send("soapenv:Body") {
xml.send("urn:VehicleDescriptionRequest"){
xml.send("urn:accountInfo")("number"=>"#{number}" "secret"=>"#{secret}" "country"=>"US" "language"=>"en" "behalfOf"=>"#{behalfOf}")
xml.send("urn:styleId"){xml.text "#{style_id}"}
xml.send("urn:switch"){xml.text "ShowAvailableEquipment"}
xml.send("urn:includeMediaGallery"){xml.text "Both"}
}
}
}
end
file_test=File.new("dummy_file", 'w')
file_test.puts builder.to_xml
builder.to_xml
end
我收到以下错误
SyntaxError: /home/aravind/Documents/dev/nthat/app/models/carinfo.rb:27: syntax error, unexpected '(', expecting '}'
... xml.send("urn:accountInfo")("number"=>"#{number}" "secret...
... ^
/home/aravind/Documents/dev/nthat/app/models/carinfo.rb:27: syntax error, unexpected =>, expecting '}'
...d("urn:accountInfo")("number"=>"#{number}" "secret"=>"#{secr...
... ^
/home/aravind/Documents/dev/nthat/app/models/carinfo.rb:27: syntax error, unexpected =>, expecting '}'
...number"=>"#{number}" "secret"=>"#{secret}" "country"=>"US" "...
... ^
/home/aravind/Documents/dev/nthat/app/models/carinfo.rb:27: syntax error, unexpected =>, expecting '}'
...ecret"=>"#{secret}" "country"=>"US" "language"=>"en" "behalf...
... ^
/home/aravind/Documents/dev/nthat/app/models/carinfo.rb:27: syntax error, unexpected =>, expecting '}'
...}" "country"=>"US" "language"=>"en" "behalfOf"=>"#{behalfOf}...
... ^
/home/aravind/Documents/dev/nthat/app/models/carinfo.rb:27: syntax error, unexpected =>, expecting '}'
..." "language"=>"en" "behalfOf"=>"#{behalfOf}")
另外我不确定如何构建这部分的XML:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:description7a.services.chrome.com">
错误直接指出问题所在。第27行..与其下面的类似行相比,该行看起来有什么不同? :) –
'(“number”=>“#{number}”“secret”=>“#{secret}”“country”=>“US”“language”=>“en”“representativeOf”=> {代表_Of}“)' 这是行。我的疑问是,如何 'build such xml –
Aravind
http://nokogiri.org /Nokogiri/XML/Builder.html –