/usr/share/doc/libjs-xmlextras/examples/usage.html is in libjs-xmlextras 20060529-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | <?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Xml Extras (WebFX)</title>
<script type="text/javascript" src="local/webfxlayout.js"></script>
</head>
<body>
<!-- WebFX Layout Include -->
<script type="text/javascript">
var articleMenu= new WebFXMenu;
articleMenu.left = 384;
articleMenu.top = 86;
articleMenu.width = 140;
articleMenu.add(new WebFXMenuItem("Xml Extras", "xmlextras.html"));
articleMenu.add(new WebFXMenuItem("Usage", "usage.html"));
articleMenu.add(new WebFXMenuItem("Demo", "demo.html"));
articleMenu.add(new WebFXMenuSeparator);
articleMenu.add(new WebFXMenuItem("Download", "/download/xmlextras.zip"));
webfxMenuBar.add(new WebFXMenuButton("Article Menu", null, null, articleMenu));
webfxLayout.writeTitle("Xml Extras");
webfxLayout.writeMenu();
webfxLayout.writeDesignedByEdger();
</script>
<div class="webfx-main-body">
<!-- end WebFX Layout Includes -->
<h2>Usage</h2>
<p>In this document we will go through some common uses of the XML objects provided
by IE and Mozilla.</p>
<p>To use the XML extras one has to include the needed JS file.</p>
<pre>
<script type="text/javascript" src="<a href="xmlextras.js">xmlextras.js</a>"></script>
</pre>
<p>Notice that this JS file uses try/catch statements and therefore it will give syntax errors
in old browsers that does not support these.</p>
<h2>Load XML File</h2>
<h3>...using asyncronous XmlHttp</h3>
<p>To load an XML file one can use both the <code>XmlHttp</code> object and the
<code>XmlDocument</code> object but I usually prefer the first one because it is a bit more
powerful.</p>
<pre>
function loadAsync(sUri) {
var xmlHttp = XmlHttp.create();
var async = true;
xmlHttp.open("GET", sUri, async);
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4)
doSomething(xmlHttp.responseXML); // responseXML : XmlDocument
}
xmlHttp.send(null);
}
</pre>
<p>The <code>open</code> method takes three arguments and the first one is either
<code>"GET"</code> or <code>"POST"</code>. The last argument allows you to load the
document synchronously or asynchronously. Synchronous loading is easier to use
because the call to <code>send</code> does not return until the XML file has loaded.
The downside to this is that the browser does not respond during this time. The argument
to <code>send</code> is needed and in case one is using <code>"POST"</code> this
should be of type <code>XmlDocument</code>.</p>
<h3>...using syncronous XmlHttp</h3>
<p>In case you want to use synchronous loading set the third argument of <code>open</code>
to <code>false</code>. Once the <code>send</code> method has been called we can access the
<code>responseXML</code> property.</p>
<pre>
function loadSync(sUri) {
var xmlHttp = XmlHttp.create();
var async = false;
xmlHttp.open("GET", sUri, async);
xmlHttp.send(null);
doSomething(xmlHttp.responseXML); // responseXML : XmlDocument
}
</pre>
<h2>Posting an XML file</h2>
<p>To post an XML document to the server we once again use the <code>XmlHttp</code> object.
To do this one only needs to pass the <code>XmlDocument</code> as the argument to the
<code>send</code> method.</p>
<pre>
function postAsync(sUri, xmlDoc) {
var xmlHttp = XmlHttp.create();
var async = true;
xmlHttp.open("GET", sUri, async);
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4)
doSomething(xmlHttp.responseXML); // responseXML : XmlDocument
}
xmlHttp.send(xmlDoc);
}
</pre>
<h2>Loading a text file</h2>
<p>The <code>XmlHttp</code> object also allows you to read non XML files. This is
done in almost exactly the same way as one reads XML files but instead of looking
at the <code>responseXML</code> property one looks at <code>responseText</code>.</p>
<pre>
function loadTextSync(sUri) {
var xmlHttp = XmlHttp.create();
var async = false;
xmlHttp.open("GET", sUri, async);
xmlHttp.send(null);
doSomething(xmlHttp.responseText); // responseText : String
}
</pre>
<h2>Using XmlDocument</h2>
<p>The <code>XmlDocument</code> can be used in almost exactly the same was as one
uses the normal <code>document</code> object in DHTML. As long as one uses standard DOM
methods and properties no problems should arise. Below is a simple example that
creates a document, parses a string and then finds all test elements and
alerts their name.</p>
<pre>
var doc = XmlDocument.create();
doc.loadXML( "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<root>" +
"<test name=\"Test 1\"/>" +
"<test name=\"Test 2\"/>" +
"</root>");
var testEls = doc.getElementsByTagName("test");
for (var i = 0; i < testEls.length; i++)
alert(tests[i].getAttribute("name"));
</pre>
<h3>Load using XmlDocument</h3>
<p>One can also load an xml file from the server using an <code>XmlDocument</code>
object. This is done using the <code>load</code> method. To make the loading asychronous
one sets the property <code>async</code> to <code>true</code> of the
<code>XmlDocument</code> object. When using asynchronous loading wait until the
<code>readyState</code> is <code>4</code>.</p>
<pre>
function loadAsync2(sUri) {
var doc = XmlDocument.create();
doc.async = true;
doc.onreadystatechange = function () {
if (doc.readyState == 4)
alert(doc.xml); // doc.xml : String
}
doc.load(sUri);
}
</pre>
<h2>Demo</h2>
<p>The demo page allows you to load a few different xml files as well as enter some text and
load non xml files. When outputting an XMl tree the xml document is traversed and some color
coded html is generated.</p>
<p><a href="demo.html">Try the demo</a></p>
<p>
<a href="xmlextras.html">Xml Extras</a><br />
<a href="usage.html">Usage</a><br />
<a href="demo.html">Demo</a><br />
<a href="/download/xmlextras.zip">Download</a>
</p>
<p class="author">Author: Erik Arvidsson</p>
<!-- end webfx-main-body -->
</div>
</body>
</html>
|