2017-05-26 72 views
0

如果我不能使其验证我的教授不会标记它,我似乎无法做到这一点,任何帮助非常感谢。我使用xmlvalidation作为我允许根据说明使用的唯一一个。XML文件不会验证到XSD

<?xml version="1.0"?> 

<MikeDawidowski xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation=" Company-withErrors.xsd"> 

    <company ORDER="1"> 
    <CompanyName>TestCompany</CompanyName> 
    <CID>1</CID> 
    <City>London</City> 
    <Prov>ON</Prov> 
    <MaterialSource> 
     <MaterialBrandName>Leather</MaterialBrandName> 
     <MaterialIdentification>105</MaterialIdentification> 
     <AssocCompID>10</AssocCompID> 
     <MaterialBrandName>Leather2</MaterialBrandName> 
     <MaterialIdentification>110</MaterialIdentification> 
     <AssocCompID>15</AssocCompID> 
    </MaterialSource> 
    <PhoneNum>5196867766</PhoneNum> 
    </company> 

</MikeDawidowski> 

,这是XSD

<?xml version="1.0"?> 

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

<xs:element name="MikeDawidowski"> 
    <xs:complexType> 
       <xs:sequence> 
       </xs:sequence> 
    </xs:complexType> 
</xs:element> 


      <xs:complexType> 
      <xs:sequence> 

       <xs:element name="CompanyName" type="xs:string" /> 

       <xs:element name="CID" type="xs:integer" /> 

       <xs:element name="City" type="xs:string" minOccurs = "0"/> 
       <xs:element name="Prov" type="xs:string" minOccurs = "0"/> 
       <xs:element name="MaterialSource" maxOccurs="5"> 
        <xs:complexType> 
        <xs:sequence> 
         <xs:element name="MaterialBrandName" type="xs:string" /> 
         <xs:element name="MaterialIdentification" type="xs:string" />      

        </xs:sequence> 
        </xs:complexType> 
       </xs:element> 

       <xs:element name="PhoneNum" type="xs:string" minOccurs = "0"/>      

      </xs:sequence> 
      <xs:attribute name="ORDER" type="xs:integer" use="optional"/> 
      </xs:complexType> 



</xs:schema> 
+0

您能否确认XSD文件名是'Company-withErrors.xsd',并且它位于与XML相同的文件夹中?注意:在'xsi:noNamespaceSchemaLocation'开头有一个空格字符。 –

+0

@beckyang是啊,我只是拿出空间,并确保在同一个文件夹中的专有名称,当我去验证我得到这些错误:XML文档中的错误: \t 22: cvc-复杂类型2.1:元素'MikeDawidowski'必须没有字符或元素信息项[子项],因为类型的内容类型为空。 文件xml架构中的错误: \t 13: s4s-att-must-appear:属性'name'必须出现在元素'complexType'中。 –

回答

0

有在XSD两种方式说一个元素的类型应该是什么样的,和你有这两者的某种混合物。首先是把类型信息的内联,在这种情况下,类型不具有名称:

<xs:element name="MikeDawidowski"> 
    <xs:complexType> 
     <xs:sequence> 
      <xs:element.... 
      <xs:element.... 
     </xs:sequence> 
    </xs:complexType> 
</xs:element> 

第二种方法是定义一个名为类型和引用它:

<xs:element name="MikeDawidowski" type="myType"/> 

<xs:complexType name="myType"> 
     <xs:sequence> 
      <xs:element.... 
      <xs:element.... 
     </xs:sequence> 
</xs:complexType> 

你已经设法将所有的类型信息从元素声明中提取出来,但是你没有真正给出这个类型的名字或者从元素声明中链接到它。