Professional Documents
Culture Documents
<html>
<head><title>Example</title></head.
<body>
<h1>This is an example of a page.</h1>
<h2>Some information goes here.</h2>
</body>
</html>
Example of an XML Document
<?xml version=“1.0”/>
<address>
<name>Alice Lee</name>
<email>alee@aol.com</email>
<phone>212-346-1234</phone>
<birthday>1985-03-22</birthday>
</address>
Difference Between HTML and XML
address
● Advanced Components
● CData Sections
● Processing Instructions
Legal Building Blocks of XML
● A Document Type Definition (DTD)
allows the developer to create a set of
rules to specify legal content and place
restrictions on an XML file
Alice Lee
alee@aol.com
123-45-6789
1983-7-15
Walking through an Example
1. Create an HTML file with notepad. Insert some
JavaScript code that will parse newspaper.xml into a
DOM tree. Print out the attribute values for each
articleID.
Parsers
var attributeValue;
//get an attribute value by specific name
attributeValue = elementNode.getAttribute("articleID");
//print it out
document.writeln("Attribute value: <b>" + attributeValue +
" </b><br>");
}
Cautions with DOM
● Make sure that the XML file resides in the same
directory as the html file with the JavaScript
code
document.getElementById("demo").innerH
TML = xhttp.responseText;