简体   繁体   中英

XML file won't validate to XSD

If I can't make it validate my prof won't mark it, and I cannot seem to make this work, any help much appreciated. I'm using xmlvalidation as its the only one I'm allowed to use according to the instructions.

    <?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>

and this is the 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>

There are two ways in XSD of saying what the type of an element should be, and you've got some mixture of the two. The first is to put the type information inline, in which case the type doesn't have a name:

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

The second way is to define a named type and refer to it:

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

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

You've somehow contrived to put all the type information out-of-line from the element declaration, but you haven't actually given the type a name or linked to it from the element declaration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM