Prepared by
Dr.M.Kaliappan.,M.E.,Ph.D
Associate Professor
Dept. of Computer Science and Engineering
Ramco Institute of Technology
Rajapalayam, Tamilnadu, India
Email: kaliappan@ritrjpm.ac.in
Well-formed XML and valid XML
documents
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
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.
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
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
Ex: Valid XML document : contactlist.xml
<?xml version=”1.0”?>
<!DOCTYPE contactlist SYSTEM “contactlist.dtd”>
<contactlist>
<fullname>Bobby Soninlaw</fullname>
<address>
<addressline1>101 South Street</addressline1>
<addressline2>Apartment #2</addressline2>
</address>
<phone>(405) 555-1234</phone>
<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
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
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
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>
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
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
3. XML preserves white spaces
–True
–false
4. What does DTD stand for?
– Direct Type Definition
– Dynamic Type Definition
– Document Type Definition
5. How XML describe data
– XML uses a DTD to describe data
– XML uses a description node to describe data
– XML uses XSL to describe data
Exercise
• Create a valid xml document for students profile

Soa unit-1-well formed and valid document08.07.2019

  • 1.
    Prepared by Dr.M.Kaliappan.,M.E.,Ph.D Associate Professor Dept.of Computer Science and Engineering Ramco Institute of Technology Rajapalayam, Tamilnadu, India Email: kaliappan@ritrjpm.ac.in Well-formed XML and valid XML documents
  • 2.
    Recap Date: 08.07.2019 XML XML delimiterscharacters:<?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 • AnXML 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 formedXML 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
  • 6.
    Ex: Valid XMLdocument : contactlist.xml <?xml version=”1.0”?> <!DOCTYPE contactlist SYSTEM “contactlist.dtd”> <contactlist> <fullname>Bobby Soninlaw</fullname> <address> <addressline1>101 South Street</addressline1> <addressline2>Apartment #2</addressline2> </address> <phone>(405) 555-1234</phone> <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
  • 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 ValidXML 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. Isthis 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 formedXML 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 XMLdocument 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
  • 12.
    3. XML preserveswhite spaces –True –false
  • 13.
    4. What doesDTD stand for? – Direct Type Definition – Dynamic Type Definition – Document Type Definition
  • 14.
    5. How XMLdescribe data – XML uses a DTD to describe data – XML uses a description node to describe data – XML uses XSL to describe data
  • 15.
    Exercise • Create avalid xml document for students profile