You are on page 1of 18

Unit IV : XML

Click to edit Master subtitle style

3/3/12

What is XML?

XML stands for EXtensible Markup Language XML is designed to transport and store data. XML is a markup language much like HTML XML was designed to carry data, not to 3/3/12 display data

The Difference Between XML and HTML


XML is not a replacement for HTML. XML and HTML were designed with different goals:

1)XML was designed to transport and store data, with focus on what data is 2)HTML was designed to display data, with focus on how data looks
3/3/12

3)HTML is about displaying

<note> <to>Person A</to> <from>Person B</from> <heading>Reminder</heading> <body> Bring my book tomorrow</body> </note> The note above is quite self descriptive. It has sender and receiver information, it also has a 3/3/12

With XML We Invent Your Own Tags The tags in the example above (like <to> and <from>) are not defined in any XML standard. These tags are "invented" by the author of the XML document. That is because the XML language has no predefined tags.
3/3/12

The tags used in HTML are

Anatomy of an XML file <?xml version="1.0"?> <EmployeeList> <!-- <Employee info> -->

3/3/12

First line says it is xml All enclosed in "EmployeeList" bracketing tags Each Employee enclosed in bracketing tags Employee has an attribute ---dept= HR
3/3/12

Document Type Definition(DTD)

The purpose of a DTD is to define the legal building blocks of an XML document. It defines the document structure with a list of legal elements. A DTD can be declared inline in your XML document(Internal DTD) or as an external reference(External DTD).
3/3/12

Internal DTD
<?xml version="1.0"?> <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to <!ELEMENT from <!ELEMENT body 3/3/12 (#PCDATA)> (#PCDATA)> (#PCDATA)>

<!ELEMENT heading (#PCDATA)>

The DTD is interpreted like this: !ELEMENT note (in line 2) defines the element "note" as having four elements: "to,from,heading,body". !ELEMENT to (in line 3) defines the "to" element to be of the type "CDATA". !ELEMENT from (in line 4) defines the "from" element to be of the type "CDATA" 3/3/12 and so on.....

External DTD

<?xml version="1.0"?>

<!DOCTYPE note SYSTEM "note.dtd"> <note> <to>Person A</to> <from>Person B</from> <heading>Reminder</heading> <body>Bring my book tomorrow</body> 3/3/12

note.dtd

<?xml version="1.0"?><!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)>

3/3/12

The building blocks of XML documents

XML documents are made up by the following building blocks: Elements Tags Attributes Entities PCDATA an CDATA 3/3/12

XML Schema

<?xml version="1.0" encoding="ISO8859-1" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/ XMLSchema">

. </xs:schema>

3/3/12

In the schema above we use the standard namespace (xs), and the URI associated with this namespace is the Schema language definition, which has the standard value of http://www.w3.org/2001/XMLSchema.

3/3/12

"shiporder" element. This element has an attribute and it contains other elements, therefore consider it as a complex type. The child elements of the "shiporder" element is surrounded by a xs:sequence element that defines an ordered sequence of sub elements: <xs:element name="shiporder"> <xs:complexType> 3/3/12

Then we have to define the "orderperson" element as a simple type (because it does not contain any attributes or other elements). The type (xs:string) is prefixed with the namespace prefix associated with XML Schema that indicates a predefined schema data type:
3/3/12

<xs:element name="orderperson" type="xs:string"/> Next, we have to define two elements that are of the complex type: "shipto" and "item". We start by defining the "shipto" element: <xs:element name="shipto"> <xs:complexType> <xs:sequence> 3/3/12 <xs:element name="name"