XML .xsd无效元素

用户名

嗨,我有一些xml,我试图将其与创建的架构一起使用,但是当我尝试解析xml时,出现以下错误消息:

The element 'PartnerPSTNTransfer' in namespace 'http://localhost/Orders-PartnerPSTNTransfer-v1-0' has invalid child element 'InstallationAddress' in namespace 'http://localhost/Orders-PartnerPSTNTransfer-v1-0'. List of possible elements expected: 'Configuration' in namespace 'http://localhost/Orders-PartnerPSTNTransfer-v1-0'.

以下是我创建的XML及其相关的架构:

XML:

<p:PartnerPSTNTransfer xmlns:padsl="http://localhost/Orders-PartnerPSTN-v1.0" 
                       xmlns:p="http://localhost/Orders-PartnerPSTNTransfer-v1-0" 
                       xmlns:a="http://localhost/Orders-Address-v1-0" 
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                       xmlns:c="http://localhost/Orders-Connection-v1-0">
  <p:TelephoneNumber>01224507392</p:TelephoneNumber>
  <p:StartDate>2014-10-25</p:StartDate>
  <p:Postcode>co27pe</p:Postcode>
  <p:InstallationAddress>
    <a:NameNumber>10</a:NameNumber>
    <a:Line1>Somewhere Road</a:Line1>
    <a:City>Somewhere City</a:City>
    <a:County>Somewhere County</a:County>
    <a:Postcode>co2 7pe</a:Postcode>
  </p:InstallationAddress>
  <p:Configuration>
    <padsl:Package>Data Only</padsl:Package>
    <padsl:Feature>F0 F1 F2</padsl:Feature>
    <padsl:Contract>Monthly_12</padsl:Contract>
  </p:Configuration>
</p:PartnerPSTNTransfer>

PartnerPSTNTransfer xsd:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="PartnerPSTNTransfer"
    targetNamespace="http://localhost/Orders-PartnerPSTNTransfer-v1-0"
    elementFormDefault="qualified"
    xmlns="http://localhost/Orders-PartnerPSTNTransfer-v1-0"
    xmlns:mstns="http://localhost/Orders-PartnerPSTNTransfer-v1-0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:a="http://localhost/Orders-Address-v1-0"
    xmlns:padsl="http://localhost/Orders-PartnerPSTN-v1.0"
    xmlns:c="http://localhost/Orders-Common-v1-0"
    xmlns:conn="http://localhost/Orders-Connection-v1-0">

  <xs:import namespace="http://localhost/Orders-Common-v1-0" schemaLocation="../../Common.xsd" />
  <xs:import namespace="http://localhost/Orders-Address-v1-0" schemaLocation="../../Address.xsd" />
  <xs:import namespace="http://localhost/Orders-PartnerPSTN-v1.0" schemaLocation="PartnerPSTN.xsd" />
  <xs:import namespace="http://localhost/Orders-Connection-v1-0" schemaLocation="../Connection.xsd" />

  <xs:complexType name="PartnerPSTNTransfer">
    <xs:sequence>
      <xs:element name="TelephoneNumber" type="c:Landline" />
      <xs:element name="StartDate" type="xs:date" />
      <xs:element name="Postcode" type="c:RequiredString" />
      <xs:element name="InstallationAddress" type="a:Address" />
      <xs:element name="Configuration" type="padsl:PartnerPSTNConfiguration" />
    </xs:sequence>
  </xs:complexType>

  <xs:element name="PartnerPSTNTransfer" type="PartnerPSTNTransfer"></xs:element>
</xs:schema>

PSTNTransfer xsd:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="PartnerPSTN"
    targetNamespace="http://localhost/Orders-PartnerPSTN-v1.0"
    elementFormDefault="qualified"
    xmlns="http://localhost/Orders-PartnerPSTN-v1.0"
    xmlns:mstns="http://localhost/Orders-PartnerPSTN-v1.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:a="http://localhost/Orders-Address-v1-0"
    xmlns:c="http://localhost/Orders-Common-v1-0" >

  <xs:import namespace="http://localhost/Orders-Common-v1-0" schemaLocation="../../Common.xsd"/>

  <xs:simpleType name="Contract">
    <xs:restriction base="xs:token">
      <xs:enumeration value="Monthly_12"></xs:enumeration>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="PackageOption">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Data Only" />
      <xs:enumeration value="Evening and Weekend" />
      <xs:enumeration value="1000 Anytime" />
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="FeatureOption">
    <xs:list>
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="F0"/>
          <xs:enumeration value="F0A"/>
          <xs:enumeration value="F0B"/>
          <xs:enumeration value="F0C"/>
          <xs:enumeration value="F1"/>
          <xs:enumeration value="F2"/>
          <xs:enumeration value="F2A"/>
          <xs:enumeration value="F3"/>
          <xs:enumeration value="F3A"/>
          <xs:enumeration value="F3B"/>
          <xs:enumeration value="F3C"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:list>
  </xs:simpleType>

  <xs:complexType name="PartnerPSTNConfiguration">
    <xs:sequence>
      <xs:element name="Package" type="PackageOption" />
      <xs:element name="Feature" type="FeatureOption" />
      <xs:element name="Contract" type="Contract" />
    </xs:sequence>
  </xs:complexType>
</xs:schema>

我在Configuration元素之前的正确位置声明了InstallationAddress元素,因此对于为什么会引发此错误感到困惑。

克休斯

用于xsi:schemaLocation向XML处理器提示http://localhost/Orders-PartnerPSTNTransfer-v1-0名称空间的XSD为PartnerPSTNTransfer.xsd

<p:PartnerPSTNTransfer xmlns:padsl="http://localhost/Orders-PartnerPSTN-v1.0" 
                       xmlns:p="http://localhost/Orders-PartnerPSTNTransfer-v1-0" 
                       xmlns:a="http://localhost/Orders-Address-v1-0" 
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                       xmlns:c="http://localhost/Orders-Connection-v1-0"
                       xsi:schemaLocation="http://localhost/Orders-PartnerPSTNTransfer-v1-0  
                                           PartnerPSTNTransfer.xsd">

做出上述更改并将问题中未包含的对XSD的悬空引用断开后,我便可以验证您的XML文件。可能是从硬盘驱动器上的意外位置拾取了旧版本的XSD。小心将XML文档实例与XSD关联的外部XML目录或其他工具机制。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

表示XSD中重复的XML元素对

来自分类Dev

XSD的XML验证:找不到元素的架构信息

来自分类Dev

XML:无效的元素

来自分类Dev

XML和XSD验证失败:元素同时具有“类型”属性和“匿名类型”子元素

来自分类Dev

使用XSD验证XML元素属性值

来自分类Dev

基于XSD生成示例XML会产生无效的整数数据

来自分类Dev

XSD错误中的XML发现无效内容

来自分类Dev

从JAVA中的XML文件打印子元素时答案无效

来自分类Dev

如何在XSD中将子XML元素与文本混合

来自分类Dev

允许通过XSD多次出现无序XML元素

来自分类Dev

验证XSD中的可选XML元素

来自分类Dev

RDF / XML rdflib:无效的属性元素URI

来自分类Dev

使用嵌套元素从XML创建XSD

来自分类Dev

基于XSD中的其他值限制XML元素值

来自分类Dev

发现XML无效的内容以元素开头。预期为“ {}”之一

来自分类Dev

使用lxml python库加载无效的Robot Framework XML模式(xsd)

来自分类Dev

无效的架构,无法从该架构源XSD生成XML数据

来自分类Dev

使用XSD验证XML。错误:无效的架构或缺少名称空间

来自分类Dev

如何在XML / XSD中获取属性的元素名称

来自分类Dev

XML XSD-允许任意的大子元素

来自分类Dev

使用xsd使xml元素唯一

来自分类Dev

XSD的XML验证:找不到元素的架构信息

来自分类Dev

使用XSD验证XML元素属性值

来自分类Dev

XSD错误中的XML错误内容无效

来自分类Dev

XML .xsd无效元素

来自分类Dev

RDF / XML rdflib:无效的属性元素URI

来自分类Dev

使用嵌套元素从XML创建XSD

来自分类Dev

XSD错误:不应使用XML元素

来自分类Dev

通过XSD仅允许XML元素中的固定文本吗?