6 // used to find the Automation server name
\r
7 function getDomDocumentPrefix() {
\r
8 if (getDomDocumentPrefix.prefix)
\r
9 return getDomDocumentPrefix.prefix;
\r
11 var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
\r
13 for (var i = 0; i < prefixes.length; i++) {
\r
15 // try to create the objects
\r
16 o = new ActiveXObject(prefixes[i] + ".DomDocument");
\r
17 return getDomDocumentPrefix.prefix = prefixes[i];
\r
22 throw new Error("Could not find an installed XML parser");
\r
25 function getXmlHttpPrefix() {
\r
26 if (getXmlHttpPrefix.prefix)
\r
27 return getXmlHttpPrefix.prefix;
\r
29 var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
\r
31 for (var i = 0; i < prefixes.length; i++) {
\r
33 // try to create the objects
\r
34 o = new ActiveXObject(prefixes[i] + ".XmlHttp");
\r
35 return getXmlHttpPrefix.prefix = prefixes[i];
\r
40 throw new Error("Could not find an installed XML parser");
\r
43 //////////////////////////
\r
44 // Start the Real stuff //
\r
45 //////////////////////////
\r
49 function XmlHttp() {}
\r
51 XmlHttp.create = function () {
\r
53 if (window.XMLHttpRequest) {
\r
54 var req = new XMLHttpRequest();
\r
56 // some versions of Moz do not support the readyState property
\r
57 // and the onreadystate event so we patch it!
\r
58 if (req.readyState == null) {
\r
60 req.addEventListener("load", function () {
\r
62 if (typeof req.onreadystatechange == "function")
\r
63 req.onreadystatechange();
\r
69 if (window.ActiveXObject) {
\r
70 return new ActiveXObject(getXmlHttpPrefix() + ".XmlHttp");
\r
75 throw new Error("Your browser does not support XmlHttp objects");
\r
78 // XmlDocument factory
\r
79 function XmlDocument() {}
\r
81 XmlDocument.create = function () {
\r
84 if (document.implementation && document.implementation.createDocument) {
\r
85 var doc = document.implementation.createDocument("", "", null);
\r
87 // some versions of Moz do not support the readyState property
\r
88 // and the onreadystate event so we patch it!
\r
89 if (doc.readyState == null) {
\r
91 doc.addEventListener("load", function () {
\r
93 if (typeof doc.onreadystatechange == "function")
\r
94 doc.onreadystatechange();
\r
100 if (window.ActiveXObject)
\r
101 return new ActiveXObject(getDomDocumentPrefix() + ".DomDocument");
\r
104 throw new Error("Your browser does not support XmlDocument objects");
\r
107 // Create the loadXML method and xml getter for Mozilla
\r
108 if (window.DOMParser &&
\r
109 window.XMLSerializer &&
\r
110 window.Node && Node.prototype && Node.prototype.__defineGetter__) {
\r
112 // XMLDocument did not extend the Document interface in some versions
\r
113 // of Mozilla. Extend both!
\r
114 //XMLDocument.prototype.loadXML =
\r
115 Document.prototype.loadXML = function (s) {
\r
117 // parse the string to a new doc
\r
118 var doc2 = (new DOMParser()).parseFromString(s, "text/xml");
\r
120 // remove all initial children
\r
121 while (this.hasChildNodes())
\r
122 this.removeChild(this.lastChild);
\r
124 // insert and import nodes
\r
125 for (var i = 0; i < doc2.childNodes.length; i++) {
\r
126 this.appendChild(this.importNode(doc2.childNodes[i], true));
\r
134 * This serializes the DOM tree to an XML String
\r
136 * Usage: var sXml = oNode.xml
\r
139 // XMLDocument did not extend the Document interface in some versions
\r
140 // of Mozilla. Extend both!
\r
142 XMLDocument.prototype.__defineGetter__("xml", function () {
\r
143 return (new XMLSerializer()).serializeToString(this);
\r
146 Document.prototype.__defineGetter__("xml", function () {
\r
147 return (new XMLSerializer()).serializeToString(this);
\r