Showing posts with label Simple XML Document with DTD. Show all posts
Showing posts with label Simple XML Document with DTD. Show all posts

Monday, May 25, 2015

Simple XML Document with DTD

Aim:
            To write a DTD for a domain specific XML document to validate the XML file.

Algorithm:

  1. Create the XML document using  <?xml version="1.0" encoding="ISO-8859-1"?> tag as the initial tab.
  2. Create another CSS document which displays the xml document details into HTML format on the browser.
  3. Give appropriate style in the CSS document.
  4. Invoke xml file from your browser.


Program:

note.xml

<?xml version="1.0" ?>
<!DOCTYPE note [
  <!ELEMENT note (to,from,heading,body)>
  <!ELEMENT to      (#PCDATA)>
  <!ELEMENT from    (#PCDATA)>
  <!ELEMENT heading (#PCDATA)>
  <!ELEMENT body    (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<message>Don't forget me this weekend!</message>
</note>



dom.xml

<html>
<body>
<h1>Mailam Engineering Collge</h1>
<p><b>To:</b> <span id="to"></span><br />
<b>From:</b> <span id="from"></span><br />
<b>Message:</b> <span id="message"></span>

<script type="text/javascript">
if (window.XMLHttpRequest)
  {
  xhttp=new XMLHttpRequest()
  }
else
  {
  xhttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
xhttp.open("GET","note.xml",false);
xhttp.send("");
xmlDoc=xhttp.responseXML;

document.getElementById("to").innerHTML=
xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
document.getElementById("from").innerHTML=
xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;
document.getElementById("message").innerHTML=
xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;
</script>

</body>
</html>