XML and XML Schema - A Refresher: CPE5009 Internet Devices and Services
XML and XML Schema - A Refresher: CPE5009 Internet Devices and Services
www.monash.edu.au
Lecture Outline
• An Overview of XML
• XML Namespaces
• XML Schema
UDDI consortium:
End Root
Element
• The terms parent, child, and sibling are used to describe the
relationships between elements. Parent elements have children.
Children on the same level are called siblings (brothers or
sisters).
• All elements can have text content and attributes (just like in
HTML).
<note date="12/11/2007">
<to>Tove</to>
<from>Jani</from>
</note>
<note>
<date>2008-01-10</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Example 1:
<person sex="female">
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
Example 2:
<person>
<sex>female</sex>
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
• This fragment:
targetNamespace="http://www.w3schools.com"
• indicates that the elements defined by this schema
(note, to, from, heading, body.) come from the
"http://www.w3schools.com" namespace.
• This fragment:
xmlns="http://www.w3schools.com"
indicates that the default namespace is
"http://www.w3schools.com".
• This fragment:
elementFormDefault="qualified"
indicates that any elements used by the XML instance
document which were declared in this schema must be
namespace qualified.
<xs:element name="library">
<xs:complexType>
<xs:sequence>
<xs:element ref="book“
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Unit intro: CSE5610 Intelligent Software Systems S1 2008 53
References
• http://www.w3schools.com/schema/default.asp
• http://www.w3schools.com/xml/default.asp
• http://www.w3schools.com/xml/xml_namespace
s.asp
• Lecture Notes from Aad Van Moorsel -
http://www.aadvanmoorsel.com/teaching.html