XSD元素命名空间验证失败

huangapple go评论60阅读模式
英文:

XSD element namespace validation failure

问题

我正在Java应用程序中工作,在其中需要显示作为一个GET REST URL执行结果的XML输出。

我遇到了以下错误:

> cvc-complex-type.2.4.a: 在元素 '{"http://www.example.org/xmlns/sapsaasconnection/SAPAriba/CATALOGCONTENT+facets_GET_Responses+286d4d67-dbb4-4187-ac9e-a9dd069c3035":Output}' 开始处发现无效内容。期望其中之一为 '{Output}'。

我的XSD如下:

<schema targetNamespace="http://www.example.org/xmlns/sapsaasconnection/SAPAriba/CATALOGCONTENT+facets_GET_Responses+286d4d67-dbb4-4187-ac9e-a9dd069c3035"
        xmlns="http://www.w3.org/2001/XMLSchema"
        xmlns:tns="http://www.example.org/xmlns/sapsaasconnection/SAPAriba/CATALOGCONTENT+facets_GET_Responses+286d4d67-dbb4-4187-ac9e-a9dd069c3035"
        >
  <complexType name="facets_GET_Responses">
    <sequence>
      <element maxOccurs="1" minOccurs="0" name="Output" type="tns:FacetResponse"/>
    </sequence>
  </complexType>
  <element name="facets_GET_Responses" type="tns:facets_GET_Responses"/>
  <complexType name="MapStringToObject">
    <all>
      <element maxOccurs="1" minOccurs="0" name="count" type="integer"/>
      <element maxOccurs="1" minOccurs="0"
               name="ClassificationCode" type="string"/>
    </all>
  </complexType>
  <element name="MapStringToObject" type="tns:MapStringToObject"/>
  <complexType name="FacetResponse">
    <all>
      <element maxOccurs="1" minOccurs="0" name="contents" type="tns:contents"/>
      <element maxOccurs="1" minOccurs="0" name="offset" type="integer"/>
      <element maxOccurs="1" minOccurs="0" name="limit" type="integer"/>
      <element maxOccurs="1" minOccurs="0"
               name="totalElements" type="integer"/>
      <element maxOccurs="1" minOccurs="0"
               name="totalPages" type="integer"/>
      <element maxOccurs="1" minOccurs="0"
               name="firstPage" type="boolean"/>
      <element maxOccurs="1" minOccurs="0" name="lastPage" type="boolean"/>
    </all>
  </complexType>
  <element name="FacetResponse" type="tns:FacetResponse"/>
  <complexType name="contents">
    <sequence>
      <element maxOccurs="unbounded" minOccurs="0"
               name="items" type="tns:MapStringToObject"/>
    </sequence>
  </complexType>
</schema>

我的XML输出如下:

<ns0:facets_GET_Responses xmlns:ns0="http://www.example.org/xmlns/sapsaasconnection/SAPAriba/CATALOGCONTENT+facets_GET_Responses+286d4d67-dbb4-4187-ac9e-a9dd069c3035">
    <ns0:Output>
        <ns0:contents>
            <ns0:items>
                <ns0:count>42</ns0:count>
                <ns0:ClassificationCode>UNSPSC:1000030</ns0:ClassificationCode>
            </ns0:items>
        </ns0:contents>
        <ns0:limit>25</ns0:limit>
        <ns0:offset>0</ns0:offset>
        <ns0:totalElements>25</ns0:totalElements>
        <ns0:totalPages>1</ns0:totalPages>
        <ns0:firstPage>true</ns0:firstPage>
        <ns0:lastPage>true</ns0:lastPage>
    </ns0:Output>
</ns0:facets_GET_Responses>

我尝试用自己的方式分析了一下,但没有找到问题在哪里。有人可以帮助解释一下XSD架构中期望的内容吗?

英文:

I am working in Java application where I need to show XML output as result of one GET REST URL execution.

I am getting error as:

> cvc-complex-type.2.4.a: Invalid content was found starting with element '{"http://www.example.org/xmlns/sapsaasconnection/SAPAriba/CATALOGCONTENT+facets_GET_Responses+286d4d67-dbb4-4187-ac9e-a9dd069c3035":Output}'. One of '{Output}' is expected.

My XSD is:

<schema targetNamespace="http://www.example.org/xmlns/sapsaasconnection/SAPAriba/CATALOGCONTENT+facets_GET_Responses+286d4d67-dbb4-4187-ac9e-a9dd069c3035"
        xmlns="http://www.w3.org/2001/XMLSchema"
        xmlns:tns="http://www.example.org/xmlns/sapsaasconnection/SAPAriba/CATALOGCONTENT+facets_GET_Responses+286d4d67-dbb4-4187-ac9e-a9dd069c3035"
        >
  <complexType name="facets_GET_Responses">
    <sequence>
      <element maxOccurs="1" minOccurs="0" name="Output" type="tns:FacetResponse"/>
    </sequence>
  </complexType>
  <element name="facets_GET_Responses" type="tns:facets_GET_Responses"/>
  <complexType name="MapStringToObject">
    <all>
      <element maxOccurs="1" minOccurs="0" name="count" type="integer"/>
      <element maxOccurs="1" minOccurs="0"
               name="ClassificationCode" type="string"/>
    </all>
  </complexType>
  <element name="MapStringToObject" type="tns:MapStringToObject"/>
  <complexType name="FacetResponse">
    <all>
      <element maxOccurs="1" minOccurs="0" name="contents" type="tns:contents"/>
      <element maxOccurs="1" minOccurs="0" name="offset" type="integer"/>
      <element maxOccurs="1" minOccurs="0" name="limit" type="integer"/>
      <element maxOccurs="1" minOccurs="0"
               name="totalElements" type="integer"/>
      <element maxOccurs="1" minOccurs="0"
               name="totalPages" type="integer"/>
      <element maxOccurs="1" minOccurs="0"
               name="firstPage" type="boolean"/>
      <element maxOccurs="1" minOccurs="0" name="lastPage" type="boolean"/>
    </all>
  </complexType>
  <element name="FacetResponse" type="tns:FacetResponse"/>
  <complexType name="contents">
    <sequence>
      <element maxOccurs="unbounded" minOccurs="0"
               name="items" type="tns:MapStringToObject"/>
    </sequence>
  </complexType>
</schema>

My XML output is:

<ns0:facets_GET_Responses xmlns:ns0="http://www.example.org/xmlns/sapsaasconnection/SAPAriba/CATALOGCONTENT+facets_GET_Responses+286d4d67-dbb4-4187-ac9e-a9dd069c3035">
    <ns0:Output>
        <ns0:contents>
            <ns0:items>
                <ns0:count>42</ns0:count>
                <ns0:ClassificationCode>UNSPSC:1000030</ns0:ClassificationCode>
            </ns0:items>
        </ns0:contents>
        <ns0:limit>25</ns0:limit>
        <ns0:offset>0</ns0:offset>
        <ns0:totalElements>25</ns0:totalElements>
        <ns0:totalPages>1</ns0:totalPages>
        <ns0:firstPage>true</ns0:firstPage>
        <ns0:lastPage>true</ns0:lastPage>
    </ns0:Output>
</ns0:facets_GET_Responses>

I tried to analyze it in my way but didn't find what's wrong here.
Can anybody help here as what is expected in XSD schema?

答案1

得分: 1

如果您希望更改您的XSD,请将elementFormDefault="unqualified"添加到schema元素。

如果您希望更改您的XML,请从除ns0:facets_GET_Responses之外的所有元素标签中删除ns0命名空间前缀。

有关elementFormDefault的详细解释,请参阅https://stackoverflow.com/q/1463138/290085。

英文:

If you wish to change your XSD, add elementFormDefault="unqualified" to the schema element.

If you wish to change your XML, remove the ns0 namespace prefix from all element tags except ns0:facets_GET_Responses.

See https://stackoverflow.com/q/1463138/290085 for detailed explanations regarding elementFormDefault.

huangapple
  • 本文由 发表于 2020年10月24日 20:25:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/64513300.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定