2. Recap
Date: 08.07.2019
XML
XML delimiters characters:<?xml version=”1.0”?>
The XML document structure consists of
The XML declaration
The Document Type Declaration
The element data
The attribute data
The character data or XML content
3. Well-formed XML
• An XML document is well formed if it follows
all the preceding syntax rules of XML.
• On the other hand, if it includes inappropriate
markup that cannot be processed by XML
parsers, the document cannot be considered
well formed.
4. A well formed XML document for describe a T-shirt
<?xml version=”1.0”?>
<Tshirt>
<model> Zippy Tee </model>
<brand> Lee </brand>
<price currency= ”USD” >14.99</price>
<fabric content= ”60%” >cotton</fabric>
<fabric content= ”40%” >polyester</fabric>
<options>
<colorOptions>
<color>red</color>
<color>white</color>
</colorOptions>
<sizeOptions>
<size>Medium</size>
<size>Large</size>
</sizeOptions>
</options>
<description>
This is a sports giant brand
</description>
</Tshirt>
XML Declaration
Root element
Child element
Attribute
value
5. Valid XML documents
• A well-formed XML document is considered
valid only if it contains a proper Document
Type declaration and if the document obeys
the constraints of that declaration .
• The constraints of the declaration will be
expressed as a DTD or an XML Schema
7. Is this a “valid" XML document?contactlist.xml
<?xml version=”1.0”?>
<!DOCTYPE contactlist SYSTEM “contactlist.dtd”>
<contactlist>
<firstname>Bobby </firstname>
<fullname>Bobby Soninlaw</fullname>
<address>
<addressline1>101 South Street</addressline1>
<addressline2>Apartment #2</addressline2>
</address>
<phone>(405) 555-1234</phone>
<pincode>626125</pincode>
<email>bs@mail.com</email>
</contactlist>
<!ELEMENT contactlist (fullname, address, phone, email) >
<!ELEMENT fullname (#PCDATA)>
<!ELEMENT address (addressline1, addressline2)>
<!ELEMENT addressline1 (#PCDATA)>
<!ELEMENT addressline2 (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
<!ELEMENT email (#PCDATA)>
contactlist.dtd
8. Well-Formed Document Valid XML Document
Well-formed documents follow all the
syntax rules of XML.
An XML document that conforms to
DTD or an XML Schema is said to be
valid XML document.
Not all well-formed XML documents
are valid XML document.
A valid XML document is also well-
formed.
Well-formed XML documents are
designed for use without any
constraints
Valid XML documents explicitly require
constraint mechanisms
It does not support advanced feature It support advanced features such as
linking mechanisms, value and range
bounding, and data typing
Difference between well-formed and valid" XML document
9. Class poll
1. Is this a "well formed" XML document?
<?xml version="1.0"?>
<message>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
10. 2. Well formed XML document means
A. it contains a root element
B. it contain an element
C. it contains one or more elements
D. must contain one or more elements and root
element must contain all other elements
11. 2. Valid XML document means (most appropriate)
A. the document has root element
B. the document contains at least one or more root
element
C. the XML document has DTD associated with it & it
complies with that DTD
D. Each element must nest inside any enclosing
element property