Connecting an xsd schema to an xml file
Xml:
<?xml version="1.0" encoding="UTF-8"?>
<students xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="students.xsd">
<student id = "1">
<name>Елизавета</name>
<surname>Карпова</surname>
<fathername>Константиновна</fathername>
<university>СпБГУ</university>
</student>
</students>
Xsd schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name = "students">
<xs:complexType>
<xs:sequence>
<xs:element name = "student">
<xs:complexType>
<xs:sequence>
<xs:element name = "name" type = "xs:string"/>
<xs:element name = "surname" type = "xs:string"/>
<xs:element name = "fathername" type = "xs:string"/>
<xs:element name = "university" type = "xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Both files are in the same folder.
Error:
Sannot find declaration of element students
The students
element is described, what's wrong?
3
Author: Александр Семпроний Гракх, 2017-03-19
1 answers
The error is that xml does not match the xsd schema:
<student id = "1">
But in the xsd schema, student
does not have the id
attribute.
Schema with added attribute id
:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name = "students" >
<xs:complexType>
<xs:sequence>
<xs:element name = "student" >
<xs:complexType>
<xs:sequence>
<xs:element name = "name" type = "xs:string"/>
<xs:element name = "surname" type = "xs:string"/>
<xs:element name = "fathername" type = "xs:string"/>
<xs:element name = "university" type = "xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:int"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
3
Author: Sv__t, 2018-08-03 15:06:36