Ruby on rails Rails将元素添加到我的XML消息中

Ruby on rails Rails将元素添加到我的XML消息中,ruby-on-rails,ruby,xml,ruby-on-rails-4,Ruby On Rails,Ruby,Xml,Ruby On Rails 4,我目前正在尝试与我们的仓库进行集成。他们有一个接受XML消息的API。但是,当我向他们发送消息(根据规范)时,我不断收到一个错误,即我的XML无效。我相信Rails正在给我的消息添加我不想要的元素。我的代码: x = ::Builder::XmlMarkup.new(:indent=>2) x.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" x.InventoryXML { x.Cu

我目前正在尝试与我们的仓库进行集成。他们有一个接受XML消息的API。但是,当我向他们发送消息(根据规范)时,我不断收到一个错误,即我的XML无效。我相信Rails正在给我的消息添加我不想要的元素。我的代码:

    x = ::Builder::XmlMarkup.new(:indent=>2)
    x.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
    x.InventoryXML {
        x.CustomerID("username")
        x.Password("password")
        x.Items {
            x.ItemID(self.name)
        }
    }

    http = Net::HTTP.new("www.webgistix.com")
    response = http.post("/XML/GetInventoryForSelectedItems.asp", x.to_xml)
    answer = self.evaluate_smartfill_response(response)
    return x.to_s + "\n Response: " + answer.to_s
当我打印报税表时,我得到的是:

<?xml version="1.0" encoding="UTF-8"?> 
<InventoryXML> 
  <CustomerID>username</CustomerID> 
  <Password>password</Password> 
  <Items> 
    <ItemID>item</ItemID> 
  </Items>         
</InventoryXML> 
<inspect/> <to_xml/> <to_s/> 

用户名
密码
项目
错误:

错误:处理您的请求时出错。请检查您的请求,然后重试


我认为在我的邮件末尾添加的标签可能是问题所在。这些标记来自何处?如何防止它们添加到我的邮件中?

我更新了代码,这似乎解决了问题:

    builder = Nokogiri::XML::Builder.new do |xml|
        xml.InventoryXML {
            xml.CustomerID("customer")
            xml.Password("password")
            xml.Items {
                xml.ItemID(self.name)
            }
        }
    end
    http = Net::HTTP.new("www.webgistix.com")
    response = http.post("/XML/GetInventoryForSelectedItems.asp", builder.to_xml)
    answer = self.evaluate_smartfill_response(response)
    return builder.to_xml + "\n\n Response: " + answer.to_s