Analyzing a Simple DTD <br /><ul><li>  Write a simple DTD, apply it to a XML document and analyze how it reacts
  XML elements must appear in the exact sequence as they are listed in the </li></ul>      ELEMENT definition<br /><ul><li...
Analyzing a Simple DTD <br /><ul><li>  “Company.dtd”
  Contains the definitions for all the elements using company element                   </li></ul>&lt;!ELEMENT Company(Nam...
Analyzing a Simple DTD <br />       Parenthetical list of child elements defined in the ELEMENT definition for <br />     ...
  Discussed with train element and DTD for examples
  Use XML and DTD containing the company info</li></li></ul><li>Analyzing a Simple DTD <br /><ul><li>  XML file that encod...
Analyzing a Simple DTD <br /><ul><li>  Our DTD will reject this XML document as invalid under a few situations
If the XML file have any text within the Company element
  Element list does not list #PCDATA for Company, so the element cannot </li></ul>   have text <br /><ul><li>If the XML fi...
If it includes sub-elementsother than the elements what we specified for </li></ul>      Company.<br />
Upcoming SlideShare
Loading in …5
×

Analyzing a Simple DTD

1,189 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,189
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
16
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Analyzing a Simple DTD

  1. 1. Analyzing a Simple DTD <br /><ul><li> Write a simple DTD, apply it to a XML document and analyze how it reacts
  2. 2. XML elements must appear in the exact sequence as they are listed in the </li></ul> ELEMENT definition<br /><ul><li> If there is a natural ordering to the elements we should follow that ordering.</li></ul> &lt;!ELEMENT Company ( Name, ContactPerson, Street, City, State, ZipCode)<br />
  3. 3. Analyzing a Simple DTD <br /><ul><li> “Company.dtd”
  4. 4. Contains the definitions for all the elements using company element </li></ul>&lt;!ELEMENT Company(Name, ContactPerson, Street, City, State, ZipCode) &gt;<br />&lt;!ELEMENT Name (#PCDATA) &gt;<br />&lt;!ELEMENT ContactPerson (#PCDATA) &gt;<br />&lt;!ELEMENT Street (#PCDATA) &gt;<br />&lt;!ELEMENT City (#PCDATA) &gt;<br />&lt;!ELEMENT State (#PCDATA) &gt;<br />&lt;!ELEMENT ZipCode (#PCDATA) &gt;<br /><ul><li> Company element must have exactly six child elements, in exactly that order, </li></ul> with no text data outside of the child elements.<br />
  5. 5. Analyzing a Simple DTD <br /> Parenthetical list of child elements defined in the ELEMENT definition for <br /> the Company element is called a sequence list. <br /><ul><li> Items in the list are always separated by commas
  6. 6. Discussed with train element and DTD for examples
  7. 7. Use XML and DTD containing the company info</li></li></ul><li>Analyzing a Simple DTD <br /><ul><li> XML file that encodes the company information for which we define the </li></ul> “company.dtd” <br />&lt;?xml version=&quot;1.0&quot;?&gt;<br />&lt;Company&gt;<br />&lt;Name&gt;XML Corporation.&lt;/Name&gt;<br />&lt;ContactPerson&gt;John Mike &lt;/ContactPerson&gt;<br />&lt;Street&gt;Wall Street&lt;/Street&gt;<br />&lt;City&gt;NewYork&lt;/City&gt;<br />&lt;State&gt;NY&lt;/State&gt;<br />&lt;ZipCode&gt;10008&lt;/ZipCode&gt;<br />&lt;/Company&gt;<br />
  8. 8. Analyzing a Simple DTD <br /><ul><li> Our DTD will reject this XML document as invalid under a few situations
  9. 9. If the XML file have any text within the Company element
  10. 10. Element list does not list #PCDATA for Company, so the element cannot </li></ul> have text <br /><ul><li>If the XML file do not have all of the sub-elements in exactly the specified </li></ul> order.<br /><ul><li>Example - if the City element is omitted the document becomes invalid
  11. 11. If it includes sub-elementsother than the elements what we specified for </li></ul> Company.<br />
  12. 12. Analyzing a Simple DTD <br /><ul><li>If, it has sub-elements that themselves have child elements.
  13. 13. All of the sub-elements are defined as #PCDATA
  14. 14. They only accept plain text and cannot accept additional markup
  15. 15. Example
  16. 16. If we break the ContactPerson element into FirstNameand LastName,</li></ul> it will become invalid. <br /><ul><li> Unlike the element list sequence, the order of the ELEMENT tags in the DTD is </li></ul> not significant<br /><ul><li> Specify them in any order within the DTD
  17. 17. We should list them in order; it is a good programming practice.
  18. 18. Look at few XML documents that are all well-formed but invalid when declared </li></ul> for our company DTD. <br />
  19. 19. Analyzing a Simple DTD <br /><ul><li>Company1.xml</li></ul>&lt;?xml version=&quot;1.0&quot;?&gt;<br />&lt;!DOCTYPE CompanySYSTEM &quot;Company.dtd“&gt;<br />&lt;Company&gt;<br />&lt;Name&gt;XML Corporation.&lt;/Name&gt;<br />&lt;ContactPerson&gt;John Mike &lt;/ContactPerson&gt;<br />&lt;City&gt;NewYork&lt;/City&gt;<br />&lt;State&gt;NY&lt;/State&gt;<br />&lt;ZipCode&gt;10008&lt;/ZipCode&gt;<br />&lt;/Company&gt;<br />Doesn’t have street element<br />Invalid<br />
  20. 20. Analyzing a Simple DTD <br /><ul><li>Company2.xml</li></ul>&lt;?xml version=&quot;1.0&quot;?&gt;<br />&lt;!DOCTYPE CompanySYSTEM &quot;Company.dtd“&gt;<br />&lt;Company&gt;<br />&lt;Name&gt;XML Corporation.&lt;/Name&gt;<br />&lt;ContactPerson&gt;John Mike &lt;/ContactPerson&gt;<br />&lt;City&gt;NewYork&lt;/City&gt;<br />&lt;State&gt;NY&lt;/State&gt;<br />&lt;ZipCode&gt;10008&lt;/ZipCode&gt;<br />&lt;Street&gt;Wall Street&lt;/Street&gt;<br />&lt;/Company&gt;<br />Street element is out of sequence. <br />Invalid<br />
  21. 21. Analyzing a Simple DTD <br /><ul><li>Company3.xml</li></ul>&lt;?xml version=&quot;1.0&quot;?&gt;<br />&lt;!DOCTYPE CompanySYSTEM &quot;Company.dtd“&gt;<br />&lt;Company&gt;<br />&lt;Name&gt;XML Corporation.&lt;/Name&gt;<br />&lt;ContactPerson&gt;John Mike &lt;/ContactPerson&gt;<br />&lt;Street&gt;Wall Street&lt;/Street&gt;<br />&lt;Street&gt;Dalal Street&lt;/Street&gt;<br />&lt;City&gt;NewYork&lt;/City&gt;<br />&lt;State&gt;NY&lt;/State&gt;<br />&lt;ZipCode&gt;10008&lt;/ZipCode&gt;<br />&lt;/Company&gt;<br />Two Street elements<br />Invalid<br />
  22. 22. Analyzing a Simple DTD <br /><ul><li>Company4.xml</li></ul>&lt;?xml version=&quot;1.0&quot;?&gt;<br />&lt;!DOCTYPE CompanySYSTEM &quot;Company.dtd“&gt;<br />&lt;Company&gt;<br />&lt;Name&gt;XML Corporation.&lt;/Name&gt;<br />&lt;ContactPerson&gt;John Mike &lt;/ContactPerson&gt;<br />&lt;Street&gt;<br /> &lt;MajorStreet&gt;Wall Street&lt;/MajorStreet&gt;<br /> &lt;MinorStreet&gt;Dalal Street&lt;/MinorStreet&gt;<br />&lt;/Street&gt;<br />&lt;City&gt;NewYork&lt;/City&gt;<br />&lt;State&gt;NY&lt;/State&gt;<br />&lt;ZipCode&gt;10008&lt;/ZipCode&gt;<br />&lt;/Company&gt;<br />Won’t able to include elements in the Street element<br />Invalid<br />
  23. 23. Analyzing a Simple DTD <br /><ul><li>Company5.xml</li></ul>&lt;?xml version=&quot;1.0&quot;?&gt;<br />&lt;!DOCTYPE CompanySYSTEM &quot;Company.dtd“&gt;<br />&lt;Company&gt; Company Details<br />&lt;Name&gt;XML Corporation.&lt;/Name&gt;<br />&lt;ContactPerson&gt;John Mike &lt;/ContactPerson&gt;<br />&lt;Street&gt;Wall Street&lt;/Street&gt;<br />&lt;City&gt;NewYork&lt;/City&gt;<br />&lt;State&gt;NY&lt;/State&gt;<br />&lt;ZipCode&gt;10008&lt;/ZipCode&gt;<br />&lt;/Company&gt;<br />PCDATA within the Company element<br />Invalid<br />

×