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