1
// This is a third party JavaScript library from
2
// http://webfx.eae.net/dhtml/xmlextras/xmlextras.html
3
// i.e. This has not been written by ThoughtWorks.
10
// used to find the Automation server name
11
function getDomDocumentPrefix() {
12
if (getDomDocumentPrefix.prefix)
13
return getDomDocumentPrefix.prefix;
15
var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
17
for (var i = 0; i < prefixes.length; i++) {
19
// try to create the objects
20
o = new ActiveXObject(prefixes[i] + ".DomDocument");
21
return getDomDocumentPrefix.prefix = prefixes[i];
26
throw new Error("Could not find an installed XML parser");
29
function getXmlHttpPrefix() {
30
if (getXmlHttpPrefix.prefix)
31
return getXmlHttpPrefix.prefix;
33
var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
35
for (var i = 0; i < prefixes.length; i++) {
37
// try to create the objects
38
o = new ActiveXObject(prefixes[i] + ".XmlHttp");
39
return getXmlHttpPrefix.prefix = prefixes[i];
44
throw new Error("Could not find an installed XML parser");
47
//////////////////////////
48
// Start the Real stuff //
49
//////////////////////////
55
XmlHttp.create = function () {
57
if (window.XMLHttpRequest) {
58
var req = new XMLHttpRequest();
60
// some versions of Moz do not support the readyState property
61
// and the onreadystate event so we patch it!
62
if (req.readyState == null) {
64
req.addEventListener("load", function () {
66
if (typeof req.onreadystatechange == "function")
67
req.onreadystatechange();
73
if (window.ActiveXObject) {
74
return new ActiveXObject(getXmlHttpPrefix() + ".XmlHttp");
79
throw new Error("Your browser does not support XmlHttp objects");
82
// XmlDocument factory
83
function XmlDocument() {}
85
XmlDocument.create = function () {
88
if (document.implementation && document.implementation.createDocument) {
89
var doc = document.implementation.createDocument("", "", null);
91
// some versions of Moz do not support the readyState property
92
// and the onreadystate event so we patch it!
93
if (doc.readyState == null) {
95
doc.addEventListener("load", function () {
97
if (typeof doc.onreadystatechange == "function")
98
doc.onreadystatechange();
104
if (window.ActiveXObject)
105
return new ActiveXObject(getDomDocumentPrefix() + ".DomDocument");
108
throw new Error("Your browser does not support XmlDocument objects");
111
// Create the loadXML method and xml getter for Mozilla
112
if (window.DOMParser &&
113
window.XMLSerializer &&
114
window.Node && Node.prototype && Node.prototype.__defineGetter__) {
116
// XMLDocument did not extend the Document interface in some versions
117
// of Mozilla. Extend both!
118
//XMLDocument.prototype.loadXML =
119
Document.prototype.loadXML = function (s) {
121
// parse the string to a new doc
122
var doc2 = (new DOMParser()).parseFromString(s, "text/xml");
124
// remove all initial children
125
while (this.hasChildNodes())
126
this.removeChild(this.lastChild);
128
// insert and import nodes
129
for (var i = 0; i < doc2.childNodes.length; i++) {
130
this.appendChild(this.importNode(doc2.childNodes[i], true));
138
* This serializes the DOM tree to an XML String
140
* Usage: var sXml = oNode.xml
143
// XMLDocument did not extend the Document interface in some versions
144
// of Mozilla. Extend both!
146
XMLDocument.prototype.__defineGetter__("xml", function () {
147
return (new XMLSerializer()).serializeToString(this);
150
Document.prototype.__defineGetter__("xml", function () {
151
return (new XMLSerializer()).serializeToString(this);
b'\\ No newline at end of file'