1

我有一个 SOAP 信封,我将在其中添加响应负载。我已经定义了命名空间:

xmlns="http://custom.nsendpoint.com/1.1" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

在响应元素中。

custom.nsendpoint.com/1.1 XSD 中有 2 个从基本类型扩展而来的元素:

  <xs:complexType name="Contact">
    <xs:annotation>
      <xs:documentation>
        A Contact
      </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="EmailAddress" type="s:ContactEmailAddress" minOccurs="0" maxOccurs="1" nillable="true" />
      <xs:element name="Address" type="s:Address" minOccurs="0" maxOccurs="1" nillable="true" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="CompanyContact">
    <xs:annotation>
      <xs:documentation>
        Company Contact type
      </xs:documentation>
    </xs:annotation>
    <xs:complexContent>
      <xs:extension base="Contact">
        <xs:sequence>
          <xs:element name="Name" type="s:CompanyName" minOccurs="1" maxOccurs="1" nillable="true" />
          <xs:element name="Type" type="s:CompanyType" minOccurs="0" maxOccurs="1" nillable="true" />
          <xs:element name="Size" type="s:CompanySize" minOccurs="0" maxOccurs="1" />
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="PersonContact">
    <xs:annotation>
      <xs:documentation>
        Person Contact type
      </xs:documentation>
    </xs:annotation>
    <xs:complexContent>
      <xs:extension base="Contact">
        <xs:sequence>
          <xs:element name="Title" type="s:PersonTitle" minOccurs="1" maxOccurs="1"/>
          <xs:element name="FirstName" type="s:PersonFirstName" minOccurs="1" maxOccurs="1" />
          <xs:element name="MiddleName" type="s:PersonMiddleName" minOccurs="0" maxOccurs="1" nillable="true" />
          <xs:element name="LastName" type="s:PersonLastName" minOccurs="1" maxOccurs="1" />
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

所以我定义了一个这样的类型:

<Contact xsi:type="PersonContact">
    <EmailAddress>foo.bar@gmail.com</EmailAddress>
    <Address>
        <Street xmlns="http://custom.nsendpoint/contacts/1.1">10 New Street</Street>
        <Suburb xmlns="http://custom.nsendpoint/contacts/1.1">Hobboken</Suburb>
        <City xmlns="http://custom.nsendpoint/contacts/1.1">New York</City>
        <State xmlns="http://custom.nsendpoint/contacts/1.1">New York</State>
        <PostCode xmlns="http://custom.nsendpoint/contacts/1.1">000000</PostCode>
        <Country xmlns="http://custom.nsendpoint/contacts/1.1">USA</Country>
    </Address>
    <Title>MR</Title>
    <FirstName>Foo</FirstName>
    <MiddleName>Jebus</MiddleName>
    <LastName>Bar</LastName>
</Contact>

据我所知,这是定义命名空间扩展的正确方法,但是当我尝试对文档进行 Spring JAXP转换时收到以下错误消息:

org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.

当我深入研究方法逻辑时,我发现它在对象上调用transform的方法上失败了,说:traverseorg.apache.xml.serializer.TreeWalker

Method threw 'org.xml.sax.SAXException' exception

如果我删除联系人类型上的xsi:前缀,错误消息就会消失。

谁能告诉我我在这里做错了什么?我只是无法弄清楚我做错了什么。

4

0 回答 0