微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

XML添加自定义xsi:type

如何解决XML添加自定义xsi:type

我正在尝试向复杂的xml元素xsi:type='sf:Total_Report__c'添加自定义sObject,下面是示例和相应的xsd

example.xml

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Body>
  <notifications xmlns="http://soap.sforce.com/2005/09/outbound">
   <SessionId xsi:nil="true"/>
   <Url>https://somerandomurl.com</Url>
   <Notification>
    <Id>04l0uioAAM</Id>
    <sObject xsi:type="sf:Total_Report__c" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
     <sf:Id>xyx033fcml98i</sf:Id>
     <sf:Name>7654</sf:Name>
    </sObject>
   </Notification>
  </notifications>
 </soapenv:Body>
</soapenv:Envelope>

模式

该架构是两个导入,如下所示:

root.xsd -- (imports) --> notifications.xsd -- (imports) --> objects.xsd

root.xsd

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:sobject.enterprise.soap.sforce.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://schemas.xmlsoap.org/soap/envelope/">
  <xsd:import schemaLocation="notifications.xsd" namespace="http://soap.sforce.com/2005/09/outbound" />
  <xsd:element name="Envelope">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="Body">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element xmlns:q1="http://soap.sforce.com/2005/09/outbound" ref="q1:notifications" />
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xs:schema>

notifications.xsd

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="http://soap.sforce.com/2005/09/outbound" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://soap.sforce.com/2005/09/outbound" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:import schemaLocation="objects.xsd" namespace="urn:sobject.enterprise.soap.sforce.com" />
  <xs:element name="notifications">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="SessionId" nillable="true" />
        <xs:element name="Url" type="xs:string" />
        <xs:element name="Notification">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Id" type="xs:string" />
              <xs:element name="sObject">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element xmlns:q1="urn:sobject.enterprise.soap.sforce.com" ref="q1:Id" />
                    <xs:element xmlns:q3="urn:sobject.enterprise.soap.sforce.com" ref="q2:Name" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

objects.xsd

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="urn:sobject.enterprise.soap.sforce.com" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:sobject.enterprise.soap.sforce.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Id" type="xs:string" />
  <xs:element name="Name" type="xs:unsignedShort" />
</xs:schema>

在notifications.xsd中,我想要像这样的sObject <sObject xsi:type="sf:Total_Report__c" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">

请让我知道,如何实现这一目标。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。