Reputation: 2827
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>
Upvotes: 2
Views: 9982
Reputation: 52848
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.
Upvotes: 3