aurelienperonnet@gmail.com | What's new? | Profile | Settings | Help | Sign out
Google
gwt-ext-ux
GWT-Ext User Extensions
  
  
  
  
    
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
/*
* These functions taken from online article here:
* http://www.webreference.com/programming/javascript/definitive2/index.html
* They are not included under the Apache license for the rest of the source.
*/

var TimelineHelper = function()
{
}

/**
* Create a new Document object. If no arguments are specified,
* the document will be empty. If a root tag is specified, the document
* will contain that single root tag. If the root tag has a namespace
* prefix, the second argument must specify the URL that identifies the
* namespace.
*/

TimelineHelper.newDocument = function(rootTagName, namespaceURL) {
if (!rootTagName) rootTagName = "";
if (!namespaceURL) namespaceURL = "";
if (document.implementation && document.implementation.createDocument) {
// This is the W3C standard way to do it
return document.implementation.createDocument(namespaceURL, rootTagName, null);
}
else { // This is the IE way to do it
// Create an empty document as an ActiveX object
// If there is no root element, this is all we have to do
var doc = new ActiveXObject("MSXML2.DOMDocument");
// If there is a root tag, initialize the document
if (rootTagName) {
// Look for a namespace prefix
var prefix = "";
var tagname = rootTagName;
var p = rootTagName.indexOf(':');
if (p != -1) {
prefix = rootTagName.substring(0, p);
tagname = rootTagName.substring(p+1);
}
// If we have a namespace, we must have a namespace prefix
// If we don't have a namespace, we discard any prefix
if (namespaceURL) {
if (!prefix) prefix = "a0"; // What Firefox uses
}
else prefix = "";
// Create the root element (with optional namespace) as a
// string of text
var text = "<" + (prefix?(prefix+":"):"") + tagname +
(namespaceURL
?(" xmlns:" + prefix + '="' + namespaceURL +'"')
:"") +
"/>";
// And parse that text into the empty document
doc.loadXML(text);
}
return doc;
}
};


/**
* Parse the XML document contained in the string argument and return
* a Document object that represents it.
*/
TimelineHelper.parseXML = function(text) {
if (typeof DOMParser != "undefined") {
// Mozilla, Firefox, and related browsers
return (new DOMParser()).parseFromString(text, "application/xml");
}
else if (typeof ActiveXObject != "undefined") {
// Internet Explorer.
var doc = TimelineHelper.newDocument(); // Create an empty document
doc.loadXML(text); // Parse text into it
return doc; // Return it
}
else {
// As a last resort, try loading the document from a data: URL
// This is supposed to work in Safari. Thanks to Manos Batsis and
// his Sarissa library (sarissa.sourceforge.net) for this technique.
var url = "data:text/xml;charset=utf-8," + encodeURIComponent(text);
var request = new XMLHttpRequest();
request.open("GET", url, false);
request.send(null);
return request.responseXML;
}
};

Show details
Hide

Change log

r94 by antonio.signore on Apr 24, 2008   Diff

 

Older revisions

All revisions of this file

File info

Size: 3228 bytes, 87 lines