我正在尝试为以下XML编写XSD,但它显示错误: - 例外:cvc-elt.1.a:找不到元素'company
的声明company.xml
<?xml version="1.0" encoding="UTF-8"?>
<Companies
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://www.w3schools.org companyxsd.xsd">
<Company>
<Companyname></Companyname>
<address></address>
</Company>
<Department>
<dname></dname>
<deptphoneno></deptphoneno>
<deptfaxno></deptfaxno>
<deptemail></deptemail>
</Department>
<Employee>
<empid></empid>
<ename></ename>
<emailid></emailid>
<phoneno></phoneno>
</Employee>
<ContractEmployee>
<name></name>
<phoneno></phoneno>
</ContractEmployee>
</Companies>
以下是我的XSD文件 的 companyxsd.xsd
<?xml version = "1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema"
elementFormDefault = "qualified">
<xs:element name = "Companies">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs = "unbounded" minOccurs = "1" name = "Comp"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name = "Company">
<xs:sequence>
<xs:element name = "Companyname" type = "xs:string"/>
<xs:element name = "address" type = "xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name = "Department">
<xs:sequence>
<xs:element name = "dname" type = "xs:string"/>
<xs:element name = "deptphoneno" type = "xs:string"/>
<xs:element name = "deptfaxno" type = "xs:string"/>
<xs:element name = "deptemail" type = "xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name = "Employee">
<xs:sequence>
<xs:element name = "empid" type = "xs:string"/>
<xs:element name = "ename" type = "xs:string"/>
<xs:element name = "emailid" type = "xs:string"/>
<xs:element name = "phoneno" type = "xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name = "ContractEmployee">
<xs:sequence>
<xs:element name = "name" type = "xs:string"/>
<xs:element name = "phoneno" type = "xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
请告诉我,我错了。我过去几天一直试图解决这个问题,我真的被困在这里。This ER diagram is used for the XML
答案 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>