找不到元素公司的声明

时间:2017-07-07 06:12:01

标签: xml xsd xsd-validation

我的xml文档company.xml,我的xsd文档companyxsd.xsd我不知道我在哪里出错。例外:cvc-elt:1.a:找不到element'company'的声明。

 <?xml version="1.0" encoding="UTF-8"?>
 <companies xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="companyxsd.xsd">
 <company>
 <companyname>capgemini</companyname>
 <address>chalapathischool</address>
 <department>
 <dname>cse</dname>
 <deptphoneno>995674314</deptphoneno>
 <deptfaxno>08776455508</deptfaxno>
 <deptemail>gvn@gmail.com</deptemail>
  <employee>
 <empid>1</empid>
 <ename>tarun</ename>
<emailid>tar@gmail.com</emailid>
<phoneno>1234567890</phoneno>
</employee>
<contractemployee>
<name>gvn</name>
 <phoneno>9989956882</phoneno>
 </contractemployee>
 </department>
 </company>
 </companies>

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="companies">
<xs:complexType>
<xs:sequence>
<xs:element name="company" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="companyname" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="department" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="dname" type="xs:string"/>
<xs:element name="deptphoneno" type="xs:integer"/>
<xs:element name="deptfaxno" type="xs:long"/>
<xs:element name="deptemail" type="xs:string"/>
<xs:element name="employee" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="empid" type="xs:integer"/>
<xs:element name="ename" type="xs:string"/>
<xs:element name="emailid" type="xs:string"/>
<xs:element name="phoneno" type="xs:long"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="contractemployee" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="phoneno" type="xs:long"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
 </xs:element>
 </xs:schema>

我确信我的所有代码都没有错,但我仍然会收到错误。如果有人知道答案,请告诉我。

1 个答案:

答案 0 :(得分:0)

下面列出了正确答案的代码

<?xml version="1.0" encoding="UTF-8"?>
<company xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="companyxsd.xsd">
<companyname>capgemini</companyname>
<address>chalapathischool</address>
<department>
<dname>cse</dname>
<deptphoneno>995674314</deptphoneno>
<deptfaxno>08776</deptfaxno>
<deptemail>gvn@gmail.com</deptemail>
<employee>
<empid>1</empid>
<ename>tarun</ename>
<emailid>tar@gmail.com</emailid>
<phoneno>1234567890</phoneno>
</employee>
<contractemployee>
<name>gvn</name>
<phoneno>9989956882</phoneno>
</contractemployee>
</department>
</company>


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="company">
<xs:complexType>
<xs:sequence>
<xs:element name="companyname" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="department" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="dname" type="xs:string"/>
<xs:element name="deptphoneno" type="xs:integer"/>
<xs:element name="deptfaxno" type="xs:long"/>
<xs:element name="deptemail" type="xs:string"/>
<xs:element name="employee" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="empid" type="xs:integer"/>
<xs:element name="ename" type="xs:string"/>
<xs:element name="emailid" type="xs:string"/>
<xs:element name="phoneno" type="xs:long"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="contractemployee" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="phoneno" type="xs:long"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>