XML XSD
XML XSD
<?xml version="1.0"?>
<beginnersbook>
<to>My Readers</to>
<from>Chaitanya</from>
<subject>A Message to my readers</subject>
<message>Welcome to beginnersbook.com</message>
</beginnersbook>
XML Schema file: bb.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://www.beginnersbook.com"
xmlns="https://www.beginnersbook.com"
elementFormDefault="qualified">
<xs:element name="beginnersbook">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="subject" type="xs:string"/>
<xs:element name="message" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Explanation:
employee.xml
1. <?xml version="1.0"?>
2. <employee
3. xmlns="http://www.javatpoint.com"
4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5. xsi:schemaLocation="http://www.javatpoint.com employee.xsd">
6.
7. <firstname>vimal</firstname>
8. <lastname>jaiswal</lastname>
9. <email>[email protected]</email>
10. </employee>
employee.xsd
1. <?xml version="1.0"?>
2. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
3. targetNamespace="http://www.javatpoint.com"
4. xmlns="http://www.javatpoint.com"
5. elementFormDefault="qualified">
6.
7. <xs:element name="employee">
8. <xs:complexType>
9. <xs:sequence>
10. <xs:element name="firstname" type="xs:string"/>
11. <xs:element name="lastname" type="xs:string"/>
12. <xs:element name="email" type="xs:string"/>
13. </xs:sequence>
14. </xs:complexType>
15. </xs:element>
16.
17. </xs:schema>
<?xml version="1.0"?>
<Staff>
<Employee>
<Name>
<Surname>Herman</Surname>
<Firstname>Ivan</Firstname>
</Name>
<Title>Dr</Title>
<Dept>INS</Dept>
<Started>01.10.88</Started>
<Email>[email protected]</Email>
<Tel>4163</Tel>
<Fax>4199</Fax>
<Building>Secondary</Building>
<Room>C112</Room>
</Employee>
</Staff>
Schemas
Like DTDs, but better:
Functionality of DTDs
XML syntax
Include:
Datatypes (more than 30 instead of 10!) that can also define the
lexical representation (must be of form dd.ddd, say)
Inheritance (can create your own datatypes)
Schema combination rules
Proper namespace support
Richer content model
Better hooks for documentation and semantics
Schema Terminology
Element and attribute types:
with text content only: simple type
with subelements and/or attributes: complex type
All attributes are of simple type
Schemas define which elements and attributes can appear
It may define new types (simple and complex)