XSD - 内容无效。

发布于 2024-12-11 02:31:28 字数 2057 浏览 0 评论 0原文

我正在尝试使用 Nokogiri Ruby 解析器读取 XSD 文件,但它抛出以下错误 Nokogiri::XML::SyntaxError (Element '{http://www.w3.org/2001/XMLSchema}element': 内容无效。预期为 (注释?, ((simpleType | complexType)?, (unique | key | keyref)*)).):

有谁知道 xsd 出了什么问题吗?

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="company_donation_request" type="company_donation_requestType" />
  <xsd:complexType name="company_donation_requestType">
    <xsd:sequence>
      <xsd:element name="order" type="orderType"></xsd:element> 
      <xsd:element name="donation" type="donationType"></xsd:element>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="donationType">
    <xsd:sequence>
      <xsd:element name="campaign_key" type="xsd:string" minOccurs="1" maxOccurs="1" >
        <xsd:restriction base="xsd:string">
            <xsd:minLength value="2"/>
            <xsd:maxLength value="255"/>
        </xsd:restriction>
      </xsd:element>
      <xsd:element name="amount" type="xsd:decimal" minOccurs="1" maxOccurs="1" ></xsd:element>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="orderType">
    <xsd:sequence>
      <xsd:element name="id" type="xsd:string" minOccurs="1" maxOccurs="1" >
        <xsd:restriction base="xsd:string">
            <xsd:minLength value="2"/>
            <xsd:maxLength value="255"/>
        </xsd:restriction>
      </xsd:element>
      <xsd:element name="fulfillment_date" type="xsd:dateTime" minOccurs="1" maxOccurs="1" >
        <xsd:restriction base="xsd:string">
            <xsd:minLength value="2"/>
            <xsd:maxLength value="255"/>
        </xsd:restriction>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>

I am trying to read an XSD file using Nokogiri Ruby parser and it throws following error
Nokogiri::XML::SyntaxError (Element '{http://www.w3.org/2001/XMLSchema}element': The content is not valid. Expected is (annotation?, ((simpleType | complexType)?, (unique | key | keyref)*)).):

Does any one know what is wrong with the xsd?

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="company_donation_request" type="company_donation_requestType" />
  <xsd:complexType name="company_donation_requestType">
    <xsd:sequence>
      <xsd:element name="order" type="orderType"></xsd:element> 
      <xsd:element name="donation" type="donationType"></xsd:element>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="donationType">
    <xsd:sequence>
      <xsd:element name="campaign_key" type="xsd:string" minOccurs="1" maxOccurs="1" >
        <xsd:restriction base="xsd:string">
            <xsd:minLength value="2"/>
            <xsd:maxLength value="255"/>
        </xsd:restriction>
      </xsd:element>
      <xsd:element name="amount" type="xsd:decimal" minOccurs="1" maxOccurs="1" ></xsd:element>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="orderType">
    <xsd:sequence>
      <xsd:element name="id" type="xsd:string" minOccurs="1" maxOccurs="1" >
        <xsd:restriction base="xsd:string">
            <xsd:minLength value="2"/>
            <xsd:maxLength value="255"/>
        </xsd:restriction>
      </xsd:element>
      <xsd:element name="fulfillment_date" type="xsd:dateTime" minOccurs="1" maxOccurs="1" >
        <xsd:restriction base="xsd:string">
            <xsd:minLength value="2"/>
            <xsd:maxLength value="255"/>
        </xsd:restriction>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回眸一笑 2024-12-18 02:31:28

您收到此错误是因为不允许将 xsd:restriction 作为 xsd:element 的子项。尝试将 xsd:restriction 添加到 xsd:simpleType,然后在 xsd:element 中指定该类型。

您可以将 xsd:simpleType 直接添加到 xsd:element 中,但由于您使用相同的限制 3 次,因此会产生更多将其放在元素之外的 simpleType 中是有意义的。

这是一个例子。我将 simpleType 命名为“stackOverflowTest”:

<xsd:schema elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="company_donation_request" type="company_donation_requestType" />
  <xsd:complexType name="company_donation_requestType">
    <xsd:sequence>
      <xsd:element name="order" type="orderType"></xsd:element> 
      <xsd:element name="donation" type="donationType"></xsd:element>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="donationType">
    <xsd:sequence>
      <xsd:element name="campaign_key" type="stackOverflowTest" minOccurs="1" maxOccurs="1"/>
      <xsd:element name="amount" type="xsd:decimal" minOccurs="1" maxOccurs="1"/>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="orderType">
    <xsd:sequence>
      <xsd:element name="id" type="stackOverflowTest" minOccurs="1" maxOccurs="1"/>      
      <xsd:element name="fulfillment_date" type="stackOverflowTest" minOccurs="1" maxOccurs="1"/>      
    </xsd:sequence>
  </xsd:complexType>
  <xsd:simpleType name="stackOverflowTest">
    <xsd:restriction base="xsd:string">
      <xsd:minLength value="2"/>
      <xsd:maxLength value="255"/>
    </xsd:restriction>  
  </xsd:simpleType>
</xsd:schema>

希望这会有所帮助。

You're getting the error because xsd:restriction is not allowed as a child of xsd:element. Try adding your xsd:restriction to an xsd:simpleType and then specifying that type in your xsd:element.

You could add the xsd:simpleType directly to the xsd:element, but since you're using the same restriction 3 times, it makes more sense to put it in a simpleType outside of the elements.

Here's an example. I named the simpleType "stackOverflowTest":

<xsd:schema elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="company_donation_request" type="company_donation_requestType" />
  <xsd:complexType name="company_donation_requestType">
    <xsd:sequence>
      <xsd:element name="order" type="orderType"></xsd:element> 
      <xsd:element name="donation" type="donationType"></xsd:element>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="donationType">
    <xsd:sequence>
      <xsd:element name="campaign_key" type="stackOverflowTest" minOccurs="1" maxOccurs="1"/>
      <xsd:element name="amount" type="xsd:decimal" minOccurs="1" maxOccurs="1"/>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="orderType">
    <xsd:sequence>
      <xsd:element name="id" type="stackOverflowTest" minOccurs="1" maxOccurs="1"/>      
      <xsd:element name="fulfillment_date" type="stackOverflowTest" minOccurs="1" maxOccurs="1"/>      
    </xsd:sequence>
  </xsd:complexType>
  <xsd:simpleType name="stackOverflowTest">
    <xsd:restriction base="xsd:string">
      <xsd:minLength value="2"/>
      <xsd:maxLength value="255"/>
    </xsd:restriction>  
  </xsd:simpleType>
</xsd:schema>

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文