xml schema
TRANSCRIPT
![Page 1: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/1.jpg)
XML Schema
![Page 2: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/2.jpg)
The First Step
• After creating the XML Schema document, you must the begin the instance document as you normally would with the XML processing instruction and appropriate root element:
<?xml version=“1.0”?>
<root_element>
<!-– statements go here -->
</root_element>
![Page 3: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/3.jpg)
The Second Step
• After including the XML PI (processing instruction) and root element, you must then specify the XML Schema namespace using the xmlns attribute along with a prefix (xsi in our case) so you can borrow elements and attributes from that namespace:
<?xml version=“1.0”?>
<root_element xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”>
<!-– statements go here -->
</root_element>
![Page 4: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/4.jpg)
The Third Step
• Next you will include the noNamespaceSchemaLocation attribute from the XML Schema namespace along with the prefix that you previously declared (xsi) and include the name of the XML Schema document you created:
<?xml version=“1.0”?>
<root_element xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:noNamespaceSchemaLocation=“filename.xsd”>
<!-– statements go here -->
</root_element>
![Page 5: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/5.jpg)
XML Schema
Getting Started
![Page 6: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/6.jpg)
The First Step
• When creating a XML Schema document, you must begin the document with the XML processing instruction and specify the version of XML that the document is based on:
<?xml version=“1.0”?>
<!-– statements go here -->
![Page 7: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/7.jpg)
The Second Step
• After including the XML PI (processing instruction), you must then initiate the XML schema document using the <schema> element. The remainder of the document will be encased inside this element.
<?xml version=“1.0”?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<!-– statements go here -->
</schema>
![Page 8: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/8.jpg)
The Third Step
• Including the <schema> element as we have done is fine but in the case of adding additional namespaces to the document, we need to expand the notation and specify the use of the XML Schema namespace so there is no confusion within the document:
<?xml version=“1.0”?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-– statements go here -->
</xsd:schema>
![Page 9: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/9.jpg)
SimpleExample.xsd• <?xml version="1.0" encoding="UTF-8"?>• <xsd:schema
xmlns:xsd="http//www.w3.org/2001/XMLSchema">• <xsd:element name="mytag">• <xsd:complextype>• <xsd:sequence>• <xsd:element name="firstname" type="xsd:string"/>• <xsd:element name="lastname" type="xsd:string"/>• </xsd:sequence>• </xsd:complextype>• </xsd:element>• </xsd:schema>
![Page 10: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/10.jpg)
SimpleExample.xml
• <?xml version="1.0" encoding="UTF-8"?>• <mytag
xmlns:xsi="http://www.w3.org/2001/XMLSchema - instance"
• xsi:noNamespaceSchemaLocation="schema.xsd">
• <firstname>john</firstname>• <lastname>doe</lastname>• </mytag>
![Page 11: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/11.jpg)
XML Schema
Defining the Root Element
![Page 12: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/12.jpg)
Defining the Root Element
• Within the <schema> element, the Root Element of the Schema (Grammar) is defined.
<?xml version=“1.0”?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element/>
<!-– or -->
<xsd:element></xsd:element>
</xsd:schema>
Elements in XML Schema are defined using <element> elements.
![Page 13: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/13.jpg)
Defining a Root Element
• To define an element such as catalog or club-database, you must include the name attribute within the <element> element.
<?xml version=“1.0”?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name=“element_name”/>
<!-– or -->
<xsd:element name=“element_name”></xsd:element>
</xsd:schema>
![Page 14: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/14.jpg)
An Example
<?xml version=“1.0”?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name=“club-database”/>
<!-- more statements go here -->
</xsd:schema>
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<!–- statements go here -->
</club-database>
XML Schema
XML File
![Page 15: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/15.jpg)
An Example
<?xml version=“1.0”?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name=“club-database”></xsd:element>
<!-- more statements go here -->
</xsd:schema>
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<!–- statements go here -->
</club-database>
XML Schema
XML File
![Page 16: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/16.jpg)
Defining a Root Element
• In addition to specifying that we are creating an element, we must also specify the type of content it will contain. In the case of a root element, the content type will be COMPLEX and we must nest the <complexType> element within the <element> element.
<xsd:element name=“element_name”>
<xsd:complexType>
<!-- more elements go here -->
</xsd:complexType>
</xsd:element>
![Page 17: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/17.jpg)
An Example
<xsd:element name=“club-database”>
<xsd:complexType>
<!-- more statements go here -->
</xsd:complexType>
</xsd:element>
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<!–- statements go here -->
</club-database>
XML Schema
XML File
![Page 18: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/18.jpg)
Defining a Root Element
• Next we must define the contents of the <complexType> element. Since it would be pointless to have a root-element without children, we must now nest a <sequence> element within the <complexType>.
<xsd:element name=“element_name”>
<xsd:complexType>
<xsd:sequence>
<!-- more elements go here -->
</xsd:sequence>
</xsd:complexType>
</xsd:element>
![Page 19: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/19.jpg)
An Example
<xsd:element name=“club-database”>
<xsd:complexType>
<xsd:sequence>
<!-- more elements go here -->
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<!–- statements go here -->
</club-database>
XML Schema
XML File
![Page 20: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/20.jpg)
Defining a Root Element
• And FINALLY, we can specify the contents that will occur within the root element using another <element> element
<xsd:element name=“element_name”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“child_element1” .../>
<xsd:element name=“child_element2” .../>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
![Page 21: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/21.jpg)
An Example
<xsd:element name=“club-database”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” .../>
<xsd:element name=“club” .../>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<club/>
<club/>
</club-database>
XML Schema
XML File
![Page 22: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/22.jpg)
An Example
<xsd:element name=“grades-roster”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“course-info” .../>
<xsd:element name=“student” .../>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<?xml version=“1.0” encoding=“UTF-8”?>
<grades-roster>
<course-info/>
<student/>
</grades-roster>
XML Schema
XML File
![Page 23: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/23.jpg)
XML Schema
Defining Children Elements
![Page 24: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/24.jpg)
Defining an Elements Content
• Defining children elements in XML Schema is similar to defining a root element with a few twists. At this point, we will assume that the only datatype available is the ‘string’ datatype which we will use in the following examples.
![Page 25: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/25.jpg)
Defining an Elements Content
• An elements content may be defined or specified in several ways. The first way is to specify it within the <element> element itself using the type attribute.
<xsd:element name=“child-element” type=“content-type”/>
![Page 26: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/26.jpg)
Defining an Element to Contain Text• To define the content of an element to be text
we would specify the type as ‘string’ and since we are using the xsd namespace we would do the following. Note that ‘string’ is case sensitive and must be entered in lowercase.
<xsd:element name=“child-element” type=“xsd:string”/>
Warning: If you forget the namespace specifier, you will get a validation error.
![Page 27: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/27.jpg)
<xsd:element name=“club-database”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”/>
<xsd:element name=“club” type=“xsd:string”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<club>Club 1</club>
<club>Club 2</club>
</club-database>
XML Schema
XML File
![Page 28: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/28.jpg)
Defining Multiples
• Elements that can appear zero or more times and elements that can appear one or more times but the way in which we do this is slightly different and involves two new attributes: minOccurs and maxOccurs. Note that the default values for these attributes is ‘1’.
![Page 29: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/29.jpg)
Defining Zero or One Element
• To define an element so that it can be optionally included, you must include attribute minOccurs within the <element> element and specify a value of ‘0’.
<xsd:element name=“element_name”> <!-- Root Element -->
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“child_element” type=“xsd:string”
minOccurs=“0”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
![Page 30: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/30.jpg)
<xsd:element name=“club-database”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”
minOccurs=“0”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database></club-database>
XML Schema
XML File
![Page 31: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/31.jpg)
<xsd:element name=“club-database”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”
minOccurs=“0”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<club>Club 1</club>
</club-database>
XML Schema
XML File
![Page 32: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/32.jpg)
<xsd:element name=“club-database”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”
minOccurs=“0”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<club>Club 1</club>
<club>Club 2</club>
</club-database>
XML Schema
XML File
This is invalid since the default
value for maxOccurs is ‘1’.
![Page 33: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/33.jpg)
Defining One or More Elements
• To define an element so that it can be optionally included, you must include attribute maxOccurs within the <element> element and specify a value of ‘unbounded’.
<xsd:element name=“element_name”> <!-- Root Element -->
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“child_element” type=“xsd:string”
maxOccurs=“unbounded”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
![Page 34: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/34.jpg)
<xsd:element name=“club-database”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”
maxOccurs=“unbounded”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<club>Club 1</club>
</club-database>
XML Schema
XML File
![Page 35: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/35.jpg)
<xsd:element name=“club-database”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”
maxOccurs=“unbounded”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<club>Club 1</club>
<club>Club 2</club>
</club-database>
XML Schema
XML File
![Page 36: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/36.jpg)
<xsd:element name=“club-database”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”
maxOccurs=“unbounded”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database></club-database>
XML Schema
XML File
This is invalid since the default value
for minOccurs is ‘1’.
![Page 37: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/37.jpg)
<xsd:element name=“element_name”> <!-- Root Element -->
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“child_element” type=“xsd:string”
minOccurs=“0” maxOccurs=“unbounded”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Defining Zero or More Elements
• To define an element so that it can be included zero or more times, both the minOccurs and maxOccurs attributes must be added along with the values ‘0’ and ‘unbounded’ respectively.
![Page 38: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/38.jpg)
<xsd:element name=“club-database”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”
minOccurs=“0” maxOccurs=“unbounded”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database></club-database>
XML Schema
XML File
![Page 39: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/39.jpg)
<xsd:element name=“club-database”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”
minOccurs=“0” maxOccurs=“unbounded”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<club>Club 1</club>
</club-database>
XML Schema
XML File
![Page 40: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/40.jpg)
<xsd:element name=“club-database”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”
minOccurs=“0” maxOccurs=“unbounded”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<club>Club 1</club>
<club>Club 2</club>
</club-database>
XML Schema
XML File
![Page 41: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/41.jpg)
<xsd:element name=“element_name”> <!-- Root Element -->
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“child_element” type=“xsd:string”
minOccurs=“n” maxOccurs=“n”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Defining A Specific Number Of Elements
we can specify a specific number of repetitions other than 1 using both the minOccurs and maxOccurs attributes.
![Page 42: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/42.jpg)
<xsd:element name=“club-database”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”
minOccurs=“2” maxOccurs=“2”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<club>Club 1</club>
<club>Club 1</club>
</club-database>
XML Schema
XML File
![Page 43: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/43.jpg)
<xsd:element name=“element_name”> <!-- Root Element -->
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“child_element” type=“xsd:string”
minOccurs=“n” maxOccurs=“y”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Defining A Specific Range Of Element Repetitions
• Unlike Relax NG and DTDs, we can specify a specific range of element repetitions other than 0 or more AND 1 or more using both the minOccurs and maxOccurs attributes.
• NOTE: minOccurs must be less than maxOccurs.
![Page 44: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/44.jpg)
<xsd:element name=“club-database”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”
minOccurs=“2” maxOccurs=“3”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<club>Club 1</club>
<club>Club 2</club>
</club-database>
XML Schema
XML File
![Page 45: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/45.jpg)
<xsd:element name=“club-database”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”
minOccurs=“2” maxOccurs=“3”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<club>Club 1</club>
<club>Club 2</club>
<club>Club 3</club>
</club-database>
XML Schema
XML File
![Page 46: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/46.jpg)
<xsd:element name=“club-database”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”
minOccurs=“2” maxOccurs=“3”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<club>Club 1</club>
</club-database>
XML Schema
XML File
This is invalid since the number of clubs
is less than the specified
minOccurs value.
![Page 47: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/47.jpg)
<xsd:element name=“club-database”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”
minOccurs=“2” maxOccurs=“3”/>
</xsd:sequence>
</xsd:complexType>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<club>Club 1</club>
<club>Club 2</club>
<club>Club 3</club>
<club>Club 4</club>
</club-database>
XML Schema
XML File
This is invalid since the number of clubs is greater than the
specified maxOccurs value.
![Page 48: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/48.jpg)
<xsd:complexType>
<xsd:sequence>
<xsd:choice>
<xsd:element name=“child_element” type=“xsd:string”/>
<xsd:element name=“child_element” type=“xsd:string”/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
Defining A Choice of Elements
• A choice of one element from a group of two or more elements can be specified within a sequence using a <choice> element
![Page 49: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/49.jpg)
<xsd:complexType>
<xsd:sequence>
<xsd:choice>
<xsd:element name=“member-name” type=“xsd:string”/>
<xsd:element name=“member-id” type=“xsd:string”/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<member-name>Joe Smith</member-name>
</club-database>
XML Schema
XML File
![Page 50: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/50.jpg)
<xsd:complexType>
<xsd:sequence>
<xsd:choice>
<xsd:element name=“member-name” type=“xsd:string”/>
<xsd:element name=“member-id” type=“xsd:string”/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<member-id>99-23455</member-id>
</club-database>
XML Schema
XML File
![Page 51: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/51.jpg)
<xsd:complexType>
<xsd:sequence>
<xsd:choice>
<xsd:element name=“member-name” type=“xsd:string”/>
<xsd:element name=“member-id” type=“xsd:string”/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database></club-database>
XML Schema
XML File
![Page 52: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/52.jpg)
<xsd:complexType>
<xsd:sequence>
<xsd:choice>
<xsd:element name=“member-name” type=“xsd:string”/>
<xsd:element name=“member-id” type=“xsd:string”/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<member-name>Joe Smith</member-name>
<member-id>99-23455</member-id>
</club-database>
XML Schema
XML File
![Page 53: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/53.jpg)
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“child_element” type=“xsd:string”/>
<xsd:sequence>
<xsd:element name=“child_element” type=“xsd:string”/>
<xsd:element name=“child_element” type=“xsd:string”/>
</xsd:sequence>
</xsd:sequence>
</xsd:complexType>
Defining A Group of Elements
• A group of elements can be specified within a sequence using an additional <sequence> element which must appear together.
![Page 54: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/54.jpg)
<xsd:complexType>
<xsd:sequence>
<xsd:choice>
<xsd:sequence>
<xsd:element name=“member-name” type=“xsd:string”/>
<xsd:element name=“member-addr” type=“xsd:string”/>
<xsd:sequence>
<xsd:element name=“member-id” type=“xsd:string”/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<member-name>Joe Smith</member-name>
<member-addr>Cupertino, CA</member-addr>
</club-database>
XML Schema
XML File
![Page 55: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/55.jpg)
<xsd:complexType>
<xsd:sequence>
<xsd:choice>
<xsd:sequence>
<xsd:element name=“member-name” type=“xsd:string”/>
<xsd:element name=“member-addr” type=“xsd:string”/>
<xsd:sequence>
<xsd:element name=“member-id” type=“xsd:string”/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<member-id> 99-23455</member-id>
</club-database>
XML Schema
XML File
![Page 56: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/56.jpg)
<xsd:complexType>
<xsd:sequence>
<xsd:choice>
<xsd:sequence>
<xsd:element name=“member-name” type=“xsd:string”/>
<xsd:element name=“member-addr” type=“xsd:string”/>
<xsd:sequence>
<xsd:element name=“member-id” type=“xsd:string”/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<member-name>Joe Smith</member-name>
<member-addr>Cupertino, CA</member-addr>
<member-id> 99-23455</member-id>
</club-database>
XML Schema
XML File
![Page 57: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/57.jpg)
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“child_element” type=“xsd:string”/>
<xsd:sequence minOccurs=“n” maxOccurs=“y”>
<xsd:element name=“child_element” type=“xsd:string”/>
<xsd:element name=“child_element” type=“xsd:string”/>
</xsd:sequence>
</xsd:sequence>
</xsd:complexType>
Defining A Repeating Group of Elements• The minOccurs and maxOccurs attributes may
be added to the <sequence> element to specify a certain number of repetitions.
![Page 58: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/58.jpg)
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”/>
<xsd:sequence minOccurs=“2” maxOccurs=“2”>
<xsd:element name=“member-name” type=“xsd:string”/>
<xsd:element name=“member-code” type=“xsd:string”/>
</xsd:sequence>
</xsd:sequence>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<club>Club 1</club>
<member-name>Name 1</member-name>
<member-code>Code 1</member-code>
<member-name>Name 2</member-name>
<member-code>Code 2</member-code>
</club-database>
XML Schema
XML File
![Page 59: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/59.jpg)
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”/>
<xsd:sequence minOccurs=“2” maxOccurs=“2”>
<xsd:element name=“member-name” type=“xsd:string”/>
<xsd:element name=“member-code” type=“xsd:string”/>
</xsd:sequence>
</xsd:sequence>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<club>Club 1</club>
<member-name>Club 2</member-name>
<member-code>Club 3</member-code>
</club-database>
XML Schema
XML File
![Page 60: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/60.jpg)
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”/>
<xsd:sequence minOccurs=“2” maxOccurs=“2”>
<xsd:element name=“member-name” type=“xsd:string”/>
<xsd:element name=“member-code” type=“xsd:string”/>
</xsd:sequence>
</xsd:sequence>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<club>Club 1</club>
<member-name>Name 1</member-name>
<member-code>Code 1</member-code>
<member-code>Code 2</member-code>
<member-name>Name 2</member-name>
</club-database>
XML Schema
XML File
![Page 61: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/61.jpg)
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”/>
<xsd:sequence minOccurs=“2” maxOccurs=“2”>
<xsd:element name=“member-name” type=“xsd:string”/>
<xsd:element name=“member-code” type=“xsd:string”/>
</xsd:sequence>
</xsd:sequence>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<club>Club 1</club>
<member-name>Name 1</member-name>
<member-code>Code 1</member-code>
<member-name>Name 2</member-name>
</club-database>
XML Schema
XML File
![Page 62: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/62.jpg)
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“club” type=“xsd:string”/>
<xsd:sequence minOccurs=“2” maxOccurs=“2”>
<xsd:element name=“member-name” type=“xsd:string”/>
<xsd:element name=“member-code” type=“xsd:string”/>
</xsd:sequence>
</xsd:sequence>
An Example
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>
<club>Club 1</club>
<member-name>Name 1</member-name>
<member-code>Code 1</member-code>
<member-code>Code 2</member-code>
</club-database>
XML Schema
XML File
![Page 63: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/63.jpg)
XML Schema
Types of Content
![Page 64: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/64.jpg)
Other Things Besides Strings
• In addition to specifying the content of an element as a string, there is a long list of Data Types that can be specified as a value for the type attribute within the <element> element.
<xsd:element name=“child-element” type=“content-type”/>
![Page 65: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/65.jpg)
Built-In Datatypes
• In addition, the built-in datatypes for XML Schema can also be classified as one of the following:
String Types
Numeric Datatypes
Date and Time Datatypes
![Page 66: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/66.jpg)
String Type
string - text – similar to CDATA in DTDs
![Page 67: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/67.jpg)
An Example: string
<?xml version=“1.0”?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name=“club-database” type=“xsd:string”/>
<!-- more statements go here -->
</xsd:schema>
<?xml version=“1.0” encoding=“UTF-8”?>
<club-database>Club Database Text</club-database>
XML Schema
XML File
![Page 68: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/68.jpg)
Numeric Datatypes
boolean - true or 1 AND false or 0.
float - IEEE single-precision 32-bit floating point - Special values: 0, -0, INF, -INF, NaN
double - IEEE double-precision 64-bit floating point - Special values: 0, -0, INF, -INF, NaN
decimal - Base type for integers. - Must support a minimum of 18 digits. - Do not support scientific notation.
INF:infinity
NaN:Not a
Number
![Page 69: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/69.jpg)
An Example: boolean
<?xml version=“1.0”?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name=“sample” type=“xsd:boolean”/>
<!-- more statements go here -->
</xsd:schema>
<?xml version=“1.0” encoding=“UTF-8”?>
<sample>true</sample>
XML Schema
XML File
<?xml version=“1.0” encoding=“UTF-8”?>
<sample>1</sample> XML File
![Page 70: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/70.jpg)
An Example: float
<?xml version=“1.0”?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name=“sample” type=“xsd:float”/>
<!-- more statements go here -->
</xsd:schema>
<?xml version=“1.0” encoding=“UTF-8”?>
<sample>-3E2</sample>
XML Schema
XML File
<?xml version=“1.0” encoding=“UTF-8”?>
<sample>6.2</sample> XML File
<?xml version=“1.0” encoding=“UTF-8”?>
<sample>3e-2</sample> XML File
![Page 71: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/71.jpg)
An Example: decimal
<?xml version=“1.0”?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name=“sample” type=“xsd:decimal”/>
<!-- more statements go here -->
</xsd:schema>
<?xml version=“1.0” encoding=“UTF-8”?>
<sample>-3.2</sample>
XML Schema
XML File
<?xml version=“1.0” encoding=“UTF-8”?>
<sample>6.01</sample> XML File
<?xml version=“1.0” encoding=“UTF-8”?>
<sample>2</sample> XML File
![Page 72: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/72.jpg)
Numeric Datatypes
integer - both positive and negative integer values
nonNegativeInteger - integer values starting at 0 through +n
positiveInteger - integer values greater than 0
negativeInteger - integer values less than 0
nonPositiveInteger - integer values starting at 0 through -n
![Page 73: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/73.jpg)
Numeric Datatypes
byte - -128 through 127
short - -32768 through 32767
int - -2147483648 through 2147483647
long - -9223372036854775808 through 9223372036854775807
![Page 74: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/74.jpg)
Numeric Datatypes
unsignedByte - 0 through 255
unsignedShort - 0 through 65535
unsignedInt - 0 through 4294967295
unsignedLong - 0 through 18446744073709551615
![Page 75: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/75.jpg)
Numeric Datatypes
base64Binary
- allows you to include binary data within the XML document using ASCII and EBCDIC characters
hexBinary
- allows you to include hex-encoded binary information within the XML document
![Page 76: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/76.jpg)
An Example: hexBinary
<?xml version=“1.0”?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name=“sample” type=“xsd:hexBinary”/>
<!-- more statements go here -->
</xsd:schema>
<?xml version=“1.0” encoding=“UTF-8”?>
<sample>0FB3</sample>
XML Schema
XML File
![Page 77: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/77.jpg)
Date and Time Datatypes
duration - A time duration;
date - A specific date; [CCYY-MM-DD]
time - A specific time; [hh:mm:ss]
dateTime - A specific instant in time; [CCYY-MM-DDThh:mm:ss] where T is the Date/Time separator
![Page 78: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/78.jpg)
An Example: date
<?xml version=“1.0”?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name=“sample” type=“xsd:date”/>
<!-- more statements go here -->
</xsd:schema>
<?xml version=“1.0” encoding=“UTF-8”?>
<sample>2003-07-29</sample>
XML Schema
XML File
![Page 79: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/79.jpg)
An Example: time
<?xml version=“1.0”?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name=“sample” type=“xsd:time”/>
<!-- more statements go here -->
</xsd:schema>
<?xml version=“1.0” encoding=“UTF-8”?>
<sample>06:58:32</sample>
XML Schema
XML File
![Page 80: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/80.jpg)
An Example: dateTime
<?xml version=“1.0”?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name=“sample” type=“xsd:dateTime”/>
<!-- more statements go here -->
</xsd:schema>
<?xml version=“1.0” encoding=“UTF-8”?>
<sample>2003-07-29T06:58:32</sample>
XML Schema
XML File
<?xml version=“1.0” encoding=“UTF-8”?>
<sample> 2003-07-29T06:58:32-05:00</sample> XML File
![Page 81: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/81.jpg)
Date and Time Datatypes
gYear - A specific Gregorian year; [CCYY]
gMonth - A specific Gregorian month; [--MM--]
gYearMonth - A specific Gregorian month/year; [CCYY-MM]
gDay - A specific Gregorian day; [----DD]
gMonthDay - A specific Gregorian month and day; [--MM-DD]
![Page 82: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/82.jpg)
An Example: gYear
<?xml version=“1.0”?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name=“sample” type=“xsd:gYear”/>
<!-- more statements go here -->
</xsd:schema>
<?xml version=“1.0” encoding=“UTF-8”?>
<sample>2003</sample>
XML Schema
XML File
![Page 83: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/83.jpg)
An Example: gMonth
<?xml version=“1.0”?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name=“sample” type=“xsd:gMonth”/>
<!-- more statements go here -->
</xsd:schema>
<?xml version=“1.0” encoding=“UTF-8”?>
<sample>--07--</sample>
XML Schema
XML File
![Page 84: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/84.jpg)
An Example: gYearMonth
<?xml version=“1.0”?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name=“sample” type=“xsd:gYearMonth”/>
<!-- more statements go here -->
</xsd:schema>
<?xml version=“1.0” encoding=“UTF-8”?>
<sample>2003-07</sample>
XML Schema
XML File
![Page 85: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/85.jpg)
An Example: gDay
<?xml version=“1.0”?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name=“sample” type=“xsd:gDay”/>
<!-- more statements go here -->
</xsd:schema>
<?xml version=“1.0” encoding=“UTF-8”?>
<sample>---29</sample>
XML Schema
XML File
![Page 86: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/86.jpg)
An Example: gMonthDay
<?xml version=“1.0”?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name=“sample” type=“xsd:gMonthDay”/>
<!-- more statements go here -->
</xsd:schema>
<?xml version=“1.0” encoding=“UTF-8”?>
<sample>--07-29</sample>
XML Schema
XML File
![Page 87: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/87.jpg)
Adding Attributes with Content
• To add an <attribute> which requires a text value, would place a type attribute with the string datatype inside the <attribute> element .
<xsd:element name=“catalog”>
<xsd:complexType>
<xsd:attribute name=“catid” type=“xsd:string”/>
</xsd:complexType>
</xsd:element>
<catalog catid=“123”> Catalog of Books </catalog>
![Page 88: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/88.jpg)
Xml processor
• Xml is parsed by a piece of software called an xml parser.
• W3c standard.• Xml parser provides an application with access
to the elements within a document.• Thus it is link between the document and the
application.
![Page 89: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/89.jpg)
Xml Processing
XMLDoc
XMLProcessor Application
Schema
![Page 90: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/90.jpg)
DOM parsers
• A DOM parser reads an entire at once and holds a corresponding tree-like structure in memory.
• Each element within the document is a node in the tree.
![Page 91: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/91.jpg)
A DOM parser’s memory structure• <?xml version =“1.0”
encoding=“utf-8”?>• <AirlineBooking>• <customerName>• <first_name>john</first_name>• <last_name>doe</last_name>• </customerName>• <date>2004-02-02</date>• <airline>United
Airlines</airline>• <flight_no>1234</flight_no>• </AirlineBooking>
AirlineBooking
datecustomerName
Flight_no
Last_name
First_name
airline
![Page 92: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/92.jpg)
SAX parsers
• A SAX parser is an event-driven parser.• It reads the document sequentially without
storing the structure into memory.• SAX is more efficient than DOM.
![Page 93: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/93.jpg)
Event sequence via SAX processing• <?xml version =“1.0”
encoding=“utf-8”?>• <CarRental>• <customerName>• John doe </customerName>• <date>2004-02-02</date>• <model>Oldsmobile
Alero</model>• </CarRental>
• Start Document• Start Element “CarRental”• Start Element “customeName”• Character Data “john Doe”• End Element “customerName”• Start Element “date”• Character Data “2004-02-02”• End Element “date”• Start Element “model”• Character Data “Oldsmobile Alero”• End Element “model”• End Element “CarRental”• End Document
![Page 94: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/94.jpg)
Presenting XML(XSL)• <?xml version="1.0" encoding="UTF-8"?>• <?xml-stylesheet type="text/xsl" href="resulttree.xsl"?>• <people>• <person born="1912">• <name>• <firstname>lalitha</firstname>• <lastname>kavitha</lastname>• </name>• <profession>teaching</profession>• </person>• <person born="1918">• <name>• <firstname>hero honda</firstname>• <lastname>jony</lastname>• </name>• <profession>se</profession>• </person>• </people>
![Page 95: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/95.jpg)
• <?xml version="1.0" encoding="UTF-8"?>• <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">• <xsl:template match="/">• <html >• <head>• <title>sports</title>• </head>• <body>• <table border="1" bgcolor="cyan">• <thead>• <tr>• <th>born</th>• <th>first name</th>• <th>last name</th>• <th>profession</th>• </tr>• </thead>• <xsl:for-each select="people/person">• <tr>• <td><xsl:value-of select="@born"/></td>• <td><xsl:value-of select="name/firstname"/></td>• <td><xsl:value-of select="name/lastname"/></td>• <td><xsl:value-of select="profession"/></td>• </tr>• </xsl:for-each>• </table>• </body>• </html>• </xsl:template>• </xsl:stylesheet>
![Page 96: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/96.jpg)
• <html>• <head>• <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">• <title>sports</title>• </head>• <body>• <table border="1" bgcolor="cyan">• <thead>• <tr>• <th>born</th>• <th>first name</th>• <th>last name</th>• <th>profession</th>• </tr>• </thead>• <tr>• <td>1912</td>• <td>lalitha</td>• <td>kavitha</td>• <td>teaching</td>• </tr>• <tr>• <td>1918</td>• <td>hero honda</td>• <td>jony</td>• <td>se</td>• </tr>• </table>• </body>• </html>
![Page 97: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/97.jpg)
Document Object Model (DOM)
• XML Documents are treated as a tree of nodes• Every item is a "node"• Child elements and enclosed text are
subnodes• W3C DOM Site: http://www.w3.org/DOM/
![Page 98: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/98.jpg)
The W3C XML DOM Objects• Element - An Element• Attribute - An attribute• Text - Text content of an element or attribute• CDATAsection - CDATA section• EntityReference - Reference to an entity• Entity - Indication of a parsed or unparsed entity• ProcessingInstruction - A processing instruction• Comment - Content of an XML comment• Document - The Document object• DocumentType - Reference to the <!DOCTYPE> element• DocumentFragment - Reference to a fragment of a document
![Page 99: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/99.jpg)
XML Document as a Tree of Nodes
• <?xml version="1.0" encoding="UTF-8"?> <DOCUMENT> <GREETING>Hello from XML</GREETING> <MESSAGE>Welcome to Programing XML in Java</MESSAGE> </DOCUMENT>
![Page 100: XML Schema](https://reader033.vdocuments.site/reader033/viewer/2022052617/546d19c2b4af9f96748b46cd/html5/thumbnails/100.jpg)
Levels of DOM• Level 0 - Early versions of DOM in web browsers• Level 1 - It concentrates on the HTML and XML
document models:– http://www.w3.org/TR/REC-DOM-Level-1/
• Level 2 - It defines a set of objects and interfaces for accessing and manipulating document object.http://www.w3.org/TR/DOM-Level-2-Core/
• Level 3 - It will address document loading and saving, as well as content models (such as DTDs and schemas) with document validation support.http://www.w3.org/TR/DOM-Level-3-Core/