Вопрос

I'm building an xml document using Nokogiri's XML Builder. I have a tag called

<InstAmt>

and I want it to be

<InstdAmt Ccy="Eur">

What do I need to add/configure to achieve this? I tried looking at the Nokogiri documentation but it only talks about attributes like class and id and that's not what I'm looking for.

The relevant portion of the builder looks like this:

            xml.PmtId{
              xml.EndToEndId "value"
              xml.InstdAmt "value"
              xml.ChrgBr "value"
            }

Any help at all would be greatly appreciated.

Это было полезно?

Решение

If you pass a hash to the method creatig the tag it will be used to create attributes:

builder = Nokogiri::XML::Builder.new do |xml|
xml.PmtId{
  xml.EndToEndId "value"
  xml.InstdAmt "value", :Ccd => 'Eur'
  xml.ChrgBr "value"
}
end

puts builder.to_xml

produces:

<?xml version="1.0"?>
<PmtId>
  <EndToEndId>value</EndToEndId>
  <InstdAmt Ccd="Eur">value</InstdAmt>
  <ChrgBr>value</ChrgBr>
</PmtId>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top