-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathSystem.Xml.debug.js
356 lines (337 loc) · 12 KB
/
System.Xml.debug.js
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
//=============================================================================
// Jocys.com JavaScript.NET Classes (In C# Object Oriented Style)
// Created by Evaldas Jocys <[email protected]>
//=============================================================================
/// <reference path="System.debug.js" />
//=============================================================================
// Namespaces
//-----------------------------------------------------------------------------
// <PropertyGroup>
// <RootNamespace>System.Xml</RootNamespace>
// <PropertyGroup>
//-----------------------------------------------------------------------------
System.Type.RegisterNamespace("System.Xml.Node");
//=============================================================================
// System.Xml
//-----------------------------------------------------------------------------
//Using XSLT to Filter and Sort Records in the Browser
//http://johnvey.com/features/deliciousdirector/xslt-filter-sort.html
System.Xml.PathToShema = "child::*[name()='DataSet']/child::*[name()='xs:shema']";
// System.Xml.PathToData = "child::*[name()='DataSet']/child::*[name()='diffgr:diffgram']";
System.Xml.PathToData = "child::*[name()='DataSet']/child::*[name()='diffgr:diffgram']";
// If DataSet was returned thru webservices use this line.
// If .AcceptChanges() on dataset was not executed then dataset also returns data difference attribute.
System.Xml.PathToDataDiff = "child::*[name()='DataSet']/child::*[name()='diffgr:diffgram']";
System.Xml.Node.parseString = function (node, name) {
/// <summary>
///
/// </summary>
// If name was submited then get sub node by name.
// Note: Don't add "/text()" to name as it will crop text!!!
if (name) node = node.selectSingleNode(name);
var results = "";
if (node !== null) {
switch (typeof node.nodeValue) {
case "object":
// Use: var nodeValue = System.Xml.Node.parseString(items[i].selectSingleNode("Name"));
//Mozilla has many textnodes with a size of 4096 chars each instead of one large one.
//They all need to be concatenated.
for (var j = 0; j < node.childNodes.length; j++) {
results += node.childNodes.item(j).nodeValue;
}
break;
// Use: var nodeValue = System.Xml.Node.parseString(items[i].selectSingleNode("Name/text()"));
case "string":
results = node.nodeValue;
break;
case "undefined":
break;
}
}
return results;
};
System.Xml.Node.parseInt = function (node, name) {
/// <summary>
///
/// </summary>
// If name was submited then get sub node by name.
//alert(node.nodeValue);
if (name) node = node.selectSingleNode(name + "/text()");
if (node === null) {
return 0;
} else {
return parseInt(node.nodeValue);
}
};
System.Xml.Node.parseUtcDate = function (node, name) {
/// <summary>
///
/// </summary>
// If name was submited then get sub node by name.
if (name) node = node.selectSingleNode(name + "/text()");
if (node === null) {
return null;
} else {
return new Date().GetFromUtcString(node.nodeValue);
}
};
System.Xml.Node.parseDateTime = function (node, name) {
/// <summary>
///
/// </summary>
// If name was submited then get sub node by name.
if (name) node = node.selectSingleNode(name + "/text()");
if (node === null) return null;
if (node.nodeValue === null) return null;
return new Date().GetFromUtcString(node.nodeValue);
};
System.Xml.Node.parseBool = function (node, name) {
/// <summary>
///
/// </summary>
// If name was submited then get sub node by name.
if (name) node = node.selectSingleNode(name + "/text()");
var results = false;
if (node !== null) {
results = System.Bool.Parse(node.nodeValue);
}
return results;
};
System.Xml.Validate = function (fileName) {
/// <summary>
///
/// </summary>
// Create an XML DOMDocument object.
var x = new ActiveXObject("MSXML2.DOMDocument");
//Load and validate the specified file into the DOM.
x.async = false;
x.validateOnParse = true;
x.resolveExternals = true;
x.load(fileName);
// Return validation results in message to the user.
if (x.parseError.errorCode !== 0) {
return "Validation failed on " + strFile +
"\n=====================" +
"\nReason: " + x.parseError.reason +
"\nSource: " + x.parseError.srcText +
"\nLine: " + x.parseError.line + "\n";
} else {
return "Validation succeeded for " + strFile +
"\n======================\n" +
x.xml + "\n";
}
};
System.Xml.XmlRequest = function (forceXml) {
/// <summary>
/// Create XML HTTP Request.
/// </summary>
if (window.ActiveXObject) {
var xmlRequest = new ActiveXObject("Msxml2.XMLHTTP");
return xmlRequest;
} else {
var xmlRequest2 = new XMLHttpRequest();
// Helps if the response from the server doesn't have an XML mime-type header.
if (forceXml === true) xmlRequest2.overrideMimeType('text/xml');
return xmlRequest2;
}
};
System.Xml.XmlDocument = function (fileName, shemaFileName) {
/// <summary>
/// Load XML Document file with XSD Shema file(optional).
/// </summary>
var xmlDocument = null;
var isIe = typeof Response === "object" ? true : window.ActiveXObject;
if (isIe) {
xmlDocument = new ActiveXObject("MSXML2.DOMDocument");
// Pattern-based selection can be based on two standards: XSLT, and XPath.
// Let's start with the more extensive one, XPath.
xmlDocument.setProperty("SelectionLanguage", "XPath");
// Load XML Shema first if specified;
if (shemaFileName) {
var xmlShema = new System.Xml.XmlSchema(shemaFileName);
xmlDocument.schemas = xmlShema;
}
// Load XML file.
if (typeof fileName === "string") {
xmlDocument.async = false;
xmlDocument.load(fileName);
}
} else {
xmlDocument = document.implementation.createDocument('', '', null);
var xmlRequest = new System.Xml.XmlRequest();
if (typeof fileName === "string") {
xmlRequest.open("GET", fileName, false);
xmlRequest.send(null);
xmlDocument = xmlRequest.responseXML;
}
}
return xmlDocument;
};
System.Xml.XmlNode = function (name, nodes) {
/// <summary>
///
/// </summary>
var topNodeName = name ? name : "Nodes";
var xmlDocument = new System.Xml.XmlDocument();
var topNode = xmlDocument.createElement(topNodeName);
xmlDocument.appendChild(topNode);
// If array of nodes was passed then add them to document.
if (typeof nodes === "object") {
var length = nodes.length;
for (var i = 0; i < length; i++) {
topNode.appendChild(nodes[i]);
}
}
return topNode;
};
System.Xml.XslTemplate = function (fileName) {
/// <summary>
/// Load XSL Template file.
/// </summary>
if (window.ActiveXObject) {
var xslDocument = new ActiveXObject('MSXML2.FreeThreadedDOMDocument');
var xslTemplate = new ActiveXObject("Msxml2.XSLTemplate");
if (fileName) {
xslDocument.async = false;
xslDocument.load(fileName);
xslDocument.setProperty("AllowDocumentFunction", true);
xslTemplate.stylesheet = xslDocument;
}
return xslTemplate;
} else {
var xmlRequest = new System.Xml.XmlRequest();
// Load XML file.
if (fileName) {
xmlRequest.open("GET", fileName, false);
xmlRequest.send(null);
xslTemplate = xmlRequest.responseXML;
}
return xslTemplate;
}
};
System.Xml.XmlSchema = function (fileName) {
/// <summary>
/// Load XSD Shema file.
/// </summary>
if (window.ActiveXObject) {
var xmlSchema = new ActiveXObject("MSXML2.XMLSchemaCache");
if (fileName) {
xmlSchema.add("", fileName);
}
return xmlSchema;
} else {
// This is non IE part!
return null;
}
};
System.Xml.XslProcessor = function (xmlObject, xslObject) {
/// <summary>
/// Load XSL Processor file.
/// </summary>
this.XmlDocument;
this.XslTemplate;
this.XslProcessor;
// Declare private variables.
var xmlDocument = xmlObject;
var xslTemplate = xslObject;
// Create XML objects if they was submited as file names (strings).
if (typeof xmlObject === "string") xmlDocument = new System.Xml.XmlDocument(xmlObject);
if (typeof xslObject === "string") xslTemplate = new System.Xml.xslTemplate(xslObject);
var xslProcessor; // = new ActiveXObject("Msxml2.IXSLProcessor");
if (window.ActiveXObject) {
xslProcessor = xslTemplate.createProcessor();
xslProcessor.input = xmlDocument;
} else {
xslProcessor = new XSLTProcessor();
xslProcessor.importStylesheet(xslObject);
}
this.XmlDocument = xmlDocument;
this.XslTemplate = xslTemplate;
this.XslProcessor = xslProcessor;
//---------------------------------------------------------
// METHOD: TransformToXmlNode
//---------------------------------------------------------
this.TransformToXmlNode = function (target) {
// Set default target.
if (target === null) target = document;
var xmlResults = new System.Xml.XmlDocument();
if (window.ActiveXObject) {
// FreeThreaded works slower because parser need to manage concurrent access among threads.
xmlResults = new ActiveXObject("Msxml2.DOMDocument");
xmlResults.resolveExternals = false;
xmlResults.validateOnParse = false;
xmlResults.async = false;
//alert("0");
//this.ClearParameters();
//alert("1");
//alert(this.XmlDocument.transformNodeToObject(this.XslTemplate.stylesheet,xmlResults));
// NOTE!!!: It will not produce an HTML DOM object if only the toplevel element of the result is <html>
//this.XslTemplate.stylesheet.("AllowDocumentFunction",true);
selection = xmlResults.selectNodes("//");
//alert("has children: "+selection.context.xml);
//xmlResults.children[0].innerHTML = "asda";
//alert("XML Results: "+typeof(xmlResults.documentElement));
var tmpDocument = target.createDocumentFragment(xmlResults.xml);
//alert("A: "+tmpDocument.getElementsByTagName("SPAN").innerHTML);
//xmlResults.save(tmpDocument);
//tmpDocument.close();
//alert("done: "+tmpDocument.documentElement.innerHTML);
return tmpDocument;
} else {
return this.XslProcessor.transformToFragment(this.XmlDocument, target);
}
};
//---------------------------------------------------------
// METHOD: TransformToNode
//---------------------------------------------------------
this.TransformToNode = function (target) {
// Set default target.
if (target === null) target = document;
var xmlResults = new System.Xml.XmlDocument();
if (window.ActiveXObject) {
var tmpDiv = target.createElement("div");
//alert(this.TransformToHtml(target));
tmpDiv.insertAdjacentHTML("beforeEnd", this.TransformToHtml(target));
return tmpDiv;
} else {
return this.XslProcessor.transformToFragment(this.XmlDocument, target);
}
};
//---------------------------------------------------------
// METHOD: TransformToHtml
//---------------------------------------------------------
this.TransformToHtml = function (target) {
// Set default target.
if (target === null) target = document;
if (window.ActiveXObject) {
this.XslProcessor.transform();
return this.XslProcessor.output;
} else {
var tmpDiv = target.createElement("div");
tmpDiv.appendChild(this.TransformToNode(target));
return tmpDiv.innerHTML;
}
};
//---------------------------------------------------------
// METHOD: AddParameter
//---------------------------------------------------------
this.AddParameter = function (parameterName, parameterValue) {
if (window.ActiveXObject) {
this.XslProcessor.addParameter(parameterName, parameterValue, "");
} else {
this.XslProcessor.setParameter(null, parameterName, parameterValue);
}
};
//---------------------------------------------------------
// METHOD: ClearParameters
//---------------------------------------------------------
this.ClearParameters = function () {
if (!window.ActiveXObject) {
this.XslProcessor.clearParameters();
}
};
//return this.XslProcessor;
};
//==============================================================================
// END
//------------------------------------------------------------------------------