我正在尝试生成这个 xml:
<ns1:type>Account</ns1:type>
<ns1:ids>2c92c0f83d60e055013d859f7f4873ee</ns1:ids>
<ns1:ids>2c92c0f83d60e055013d859f7f2f73ec</ns1:ids>
我正在使用这段代码:
def generate_id_xml
xml = Builder::XmlMarkup.new
xml.__send__(self.ons, :type, self.remote_name)
objects.each do |o|
xml.__send__(self.ons, :ids, o.id)
end
xml.xml
end
但它正在生产:
<ins1:type>Account</ins1:type>
<ins1:ids>2c92c0f93d60e66d013d83e5845e04bc</ins1:ids
<ins1:ids>2c92c0f93d60e66d013d83e5847904be</ins1:ids>
<xml/>
为什么要添加 xml/ 有没有办法摆脱它?
我有这段代码,它没有将 xml/ 标签添加到它的输出中。
def generate_xml
xml = Builder::XmlMarkup.new
objects.each do |o|
generate_object xml, o
end
xml.xml
end
#generate xml for an object
def generate_object(builder, object)
builder.__send__(self.zns, :zObjects, 'xsi:type' => "ins1:#{self.remote_name}") do |a|
object.to_hash.each do |k,v|
a.__send__(self.ons, k.to_s.zuora_camelize.to_sym, v) unless v.nil?
end
end
end