|
Note: XML is much like HTML, but for the purpose
of organizing information vs. displaying information.
Embedded XML in an HTML Page
<html>
<head><title>Calculus MathML Example</title></head>
<body>
<math">
<mrow>
<msubsup>
<mo>∫</mo>
<mn>0</mn>
<mrow>
<mn>1</mn>
<mo>-</mo>
<mi>y</mi>
</mrow>
</msubsup>
<msqrt>
<mrow>
<mn>4</mn>
<mo>⁢</mo>
<msup>
<mi>x</mi>
<mn>2</mn>
</msup>
<mo>+</mo>
<mi>y</mi>
</mrow>
</msqrt>
<mo>δ</mo>
<mi>x</mi>
</mrow>
</math>
</body>
</html>
XML Pulled into an HTML Document From Outside
HTML Document:
---------------------------------------------------------------------------------------------------------------
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- Fig. 20.15 : DOMExample.html -->
<!-- DOM with JavaScript -->
<head>
<title>A DOM Example</title>
</head>
<body>
<script type = "text/javascript" language = "JavaScript">
<!--
var xmlDocument = new ActiveXObject( "Microsoft.XMLDOM" );
xmlDocument.load( "article.xml" );
// get the root element
var element = xmlDocument.documentElement;
document.writeln(
"<p>Here is the root node of the document: " +
"<strong>" + element.nodeName + "</strong>" +
"<br />The following are its child elements:" +
"</p><ul>" );
// traverse all child nodes of root element
for ( var i = 0; i < element.childNodes.length; i++ ) {
var curNode = element.childNodes.item( i );
// print node name of each child element
document.writeln( "<li><strong>" + curNode.nodeName
+ "</strong></li>" );
}
document.writeln( "</ul>" );
// get the first child node of root element
var currentNode = element.firstChild;
document.writeln( "<p>The first child of root node is: " +
"<strong>" + currentNode.nodeName + "</strong>" +
"<br />whose next sibling is:" );
// get the next sibling of first child
var nextSib = currentNode.nextSibling;
document.writeln( "<strong>" + nextSib.nodeName +
"</strong>.<br />Value of <strong>" +
nextSib.nodeName + "</strong> element is: " );
var value = nextSib.firstChild;
// print the text value of the sibling
document.writeln( "<em>" + value.nodeValue + "</em>" +
"<br />Parent node of <strong>" + nextSib.nodeName +
"</strong> is: <strong>" +
nextSib.parentNode.nodeName + "</strong>.</p>" );
-->
</script>
</body>
</html>
------------------------------------------------------------------------------------------------------------
XML Document:
<?xml version = "1.0"?>
<!-- Fig. 20.1: article.xml -->
<!-- Article structured with XML -->
<article>
<title>Simple XML</title>
<date>September 19, 2001</date>
<author>
<firstName>Tem</firstName>
<lastName>Nieto</lastName>
</author>
<summary>XML is pretty easy.</summary>
<content>Once you have mastered XHTML, XML is easily
learned. You must remember that XML is not for
displaying information but for managing information.
</content>
</article>
|