|
XML Processing using the Whitebeam Environment
|
Example
The following simple example shows a JavaScript recursive function that
gets the tag tree for the XML tag called 'root' (a dummy table) and then
provides a summary of the tree in the web page output.
<html>
<head>
<title>Partners</title>
</head>
<table rb:id="root">
<tr>
<th>Head 1</th>
<th>Head 2</th>
<th>Head 3</th>
</tr>
<tr>
<td>row 1, col 1</td>
<td>row 1, col 2</td>
<td>row 1, col 3</td>
</tr>
</table>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0"
marginheight="0" text="#000000" >
<H1>Decoding form parameters.</H1>
<h1 rb:id="HelloWorld">HEADER</h1>
<rb:script>
// define a function to dump one level of the XML tree.
function dumpTree(tag, spaces) {
var child;
rb.debug.write("<p>tag type:"+tag.type+", length="+
tag.length+"</p>");
if (tag.type == "tag") {
// Its an object so dump its name then recursively
// display its children.
rb.page.write("--->"+spaces+"XML Tag:"+
tag.name+"<br>");
for (child in tag) {
rb.debug.write("<p>Processing child object:"+
tag[child].type+"</p>");
dumpTree(tag[child], spaces+" ");
}
}
else {
rb.page.write("--->"+spaces+"Text,
length"+tag.length+"<br>");
}
}
var tag = rb.xml.root.findId("root");
rb.page.write("<p>\n");
rb.page.write("<h1>Tag Tree Dump</H1><P>");
rb.page.write('<table border="1">\n');
dumpTree(tag,"tag");
rb.page.write('</table>\n');
rb.page.write("<h1>Tag Tree Dump Complete</H1><P>");
</rb:script>
</body>
</html>
|
|
(loadtime : 8ms) |