2011-10-20 48 views
2

我试图用引入nokogiri ruby​​解析器读取XSD文件和它抛出以下错误 引入nokogiri :: XML :: SyntaxError错误(元素“{http://www.w3.org/2001/XMLSchema}element”:内容((simpleType | complexType)?,(unique | key | keyref)*))。):XSD - 内容无效。

是否有人知道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> 

回答

3

你得到的错误,因为xsd:restriction不允许作为xsd:element一个孩子。尝试将xsd:restriction添加到xsd:simpleType,然后在您的xsd:element中指定该类型。

可以直接添加xsd:simpleTypexsd:element,但因为你是使用相同的限制的3倍,这更有意义,把它放在一个简单类型的元素之外。

下面是一个例子。我将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> 

希望这会有所帮助。