如何在Savon 2.3中添加嵌套属性?

时间:2014-01-19 02:05:07

标签: savon

使用Savon 2.1:属性!在嵌套的xml标记中添加属性。怎么在2.3中完成?完全相同的哈希不会呈现相同的xml。

{
  :person => {
    :address => "",
    :attributes! => { :address => { :id => 44 } }
  },
  :attributes! => { :person => { :id => 666 } }
}

创建

 <person>
    <address id="44"/>
  </person>
  <attributes>
    <person>
      <id>666</id>
    </person>
  </attributes>

而不是

<person id=\"666\"><address id=\"44\"></address></person>

供参考: How do I use savon nested attributes! hash?

甚至内在属性的另一个例子!失败

{
  'Objects' => [{
    'EmailAddress' => 'CreatedUser@test.com',
    :attributes! => {
      'EmailAddress' => { 'xsi:type' => "tns:email" }
    }
  }],
  :attributes! => {
    'Objects' => { 'xsi:type' => "tns:Subscriber" },
  }
}

产地:

  <Objects>
    <EmailAddress>CreatedUser@test.com</EmailAddress>
    <attributes>
      <EmailAddress>
        <xsi:type>tns:email</xsi:type>
      </EmailAddress>
    </attributes>
  </Objects>
  <attributes>
    <Objects>
      <xsi:type>tns:Subscriber</xsi:type>
    </Objects>
  </attributes>

稍后的示例和问题的最终推理是尝试为ExactTarget创建订阅者。

https://webservice.exacttarget.com/etframework.wsdl

 61 def soap
 62   @soap_client ||= Savon.client(
 63     soap_header:  header,
 64     wsdl:           'https://webservice.exacttarget.com/etframework.wsdl',
 65     endpoint:     endpoint,
 66     wsse_auth:    ["*", "*"],
 67     raise_errors: false,
 68     log:          true,
 69     open_timeout: 180,
 70     read_timeout: 180,
 71     pretty_print_xml: true
 72   )
 73 end

 112 def create_subscriber
 113   soap.call :create, :message => {
 114     'Objects' => [{
 115       'EmailAddress' => 'CreatedUser@test.com'
 116     }],
 117     :attributes! => {
 118       'Objects' => { 'xsi:type' => "tns:Subscriber" },
 119     }
 120   }
 121 end

标题已省略,因为它包含凭据。

1 个答案:

答案 0 :(得分:4)

我最终变得如此:

   soap.call :create, :message => {
     'Objects' => [{
       'EmailAddress' => 'CreatedUser@test.com',
       :'@xsi:type'   => "tns:Subscriber"
     }]
   }

使用@

将属性标记在同一级别