1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-08-31 13:32:46 +00:00
TiddlyWiki5/tw2/source/tiddlywiki/tests/js/xml.js
Jeremy Ruston a1c8ac624f Added first pass at support for building TiddlyWiki 2.6.x with TW5
There are still some whitespace and attribute ordering issues, but the
result runs correctly.
2012-05-29 22:02:38 +01:00

37 lines
922 B
JavaScript
Executable File

tests_xml = {
parse: function(text) {
var doc;
if(window.ActiveXObject) {
doc = new ActiveXObject("Microsoft.XMLDOM");
doc.async = "false";
doc.loadXML(text);
} else {
var parser = new DOMParser();
doc = parser.parseFromString(text,"text/xml");
}
if(!doc) {
return null;
}
doc.xpath = function(expression, type) {
var t;
if(type == "string") { t = XPathResult.STRING_TYPE; }
if(type == "number") { t = XPathResult.NUMBER_TYPE; }
if(type == "boolean") { t = XPathResult.BOOLEAN_TYPE; }
if(type == "singlenode") { t = XPathResult.SINGLENODE_TYPE; }
var res = this.evaluate(expression, this, null, t, null);
if(type == "string") { return res.stringValue; }
if(type == "number") { return res.numberValue; }
if(type == "boolean") { return res.booleanValue; }
if(type == "singleNode") { return this.singleNodeValue; }
return null;
};
return doc;
}
};