XSD - 内容无效。
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您收到此错误是因为不允许将
xsd:restriction
作为xsd:element
的子项。尝试将xsd:restriction
添加到xsd:simpleType
,然后在xsd:element
中指定该类型。您可以将
xsd:simpleType
直接添加到xsd:element
中,但由于您使用相同的限制 3 次,因此会产生更多将其放在元素之外的 simpleType 中是有意义的。这是一个例子。我将 simpleType 命名为“stackOverflowTest”:
希望这会有所帮助。
You're getting the error because
xsd:restriction
is not allowed as a child ofxsd:element
. Try adding yourxsd:restriction
to anxsd:simpleType
and then specifying that type in yourxsd:element
.You could add the
xsd:simpleType
directly to thexsd: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":
Hope this helps.