XML名称空间扩展在SOAP信封中导致NAMESPACE_ERR

时间:2013-06-09 23:46:33

标签: java xml spring soap xalan

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

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

在响应元素中。

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

  <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 transform时,我收到以下错误消息:

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方法逻辑时,我看到它在traverse对象上调用的org.apache.xml.serializer.TreeWalker方法失败,并说:

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

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

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

0 个答案:

没有答案