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>
You’re getting the error because
xsd:restrictionis not allowed as a child ofxsd:element. Try adding yourxsd:restrictionto anxsd:simpleTypeand then specifying that type in yourxsd:element.You could add the
xsd:simpleTypedirectly 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.