tiddlywiki-production
Version:
a non-linear personal web notebook
1 lines • 84.8 kB
JavaScript
$tw.preloadTiddler({"title":"$:/plugins/tiddlywiki/xmldom","name":"xmldom","description":"xmldom library","list":"readme license","version":"5.1.22","plugin-type":"plugin","dependents":"","type":"application/json","text":"{\"tiddlers\":{\"$:/plugins/tiddlywiki/xmldom/dom\":{\"text\":\"/*\\n * DOM Level 2\\n * Object DOMException\\n * @see http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html\\n * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/ecma-script-binding.html\\n */\\n\\nfunction copy(src,dest){\\n\\tfor(var p in src){\\n\\t\\tdest[p] = src[p];\\n\\t}\\n}\\n/**\\n^\\\\w+\\\\.prototype\\\\.([_\\\\w]+)\\\\s*=\\\\s*((?:.*\\\\{\\\\s*?[\\\\r\\\\n][\\\\s\\\\S]*?^})|\\\\S.*?(?=[;\\\\r\\\\n]));?\\n^\\\\w+\\\\.prototype\\\\.([_\\\\w]+)\\\\s*=\\\\s*(\\\\S.*?(?=[;\\\\r\\\\n]));?\\n */\\nfunction _extends(Class,Super){\\n\\tvar pt = Class.prototype;\\n\\tif(Object.create){\\n\\t\\tvar ppt = Object.create(Super.prototype)\\n\\t\\tpt.__proto__ = ppt;\\n\\t}\\n\\tif(!(pt instanceof Super)){\\n\\t\\tfunction t(){};\\n\\t\\tt.prototype = Super.prototype;\\n\\t\\tt = new t();\\n\\t\\tcopy(pt,t);\\n\\t\\tClass.prototype = pt = t;\\n\\t}\\n\\tif(pt.constructor != Class){\\n\\t\\tif(typeof Class != 'function'){\\n\\t\\t\\tconsole.error(\\\"unknow Class:\\\"+Class)\\n\\t\\t}\\n\\t\\tpt.constructor = Class\\n\\t}\\n}\\nvar htmlns = 'http://www.w3.org/1999/xhtml' ;\\n// Node Types\\nvar NodeType = {}\\nvar ELEMENT_NODE = NodeType.ELEMENT_NODE = 1;\\nvar ATTRIBUTE_NODE = NodeType.ATTRIBUTE_NODE = 2;\\nvar TEXT_NODE = NodeType.TEXT_NODE = 3;\\nvar CDATA_SECTION_NODE = NodeType.CDATA_SECTION_NODE = 4;\\nvar ENTITY_REFERENCE_NODE = NodeType.ENTITY_REFERENCE_NODE = 5;\\nvar ENTITY_NODE = NodeType.ENTITY_NODE = 6;\\nvar PROCESSING_INSTRUCTION_NODE = NodeType.PROCESSING_INSTRUCTION_NODE = 7;\\nvar COMMENT_NODE = NodeType.COMMENT_NODE = 8;\\nvar DOCUMENT_NODE = NodeType.DOCUMENT_NODE = 9;\\nvar DOCUMENT_TYPE_NODE = NodeType.DOCUMENT_TYPE_NODE = 10;\\nvar DOCUMENT_FRAGMENT_NODE = NodeType.DOCUMENT_FRAGMENT_NODE = 11;\\nvar NOTATION_NODE = NodeType.NOTATION_NODE = 12;\\n\\n// ExceptionCode\\nvar ExceptionCode = {}\\nvar ExceptionMessage = {};\\nvar INDEX_SIZE_ERR = ExceptionCode.INDEX_SIZE_ERR = ((ExceptionMessage[1]=\\\"Index size error\\\"),1);\\nvar DOMSTRING_SIZE_ERR = ExceptionCode.DOMSTRING_SIZE_ERR = ((ExceptionMessage[2]=\\\"DOMString size error\\\"),2);\\nvar HIERARCHY_REQUEST_ERR = ExceptionCode.HIERARCHY_REQUEST_ERR = ((ExceptionMessage[3]=\\\"Hierarchy request error\\\"),3);\\nvar WRONG_DOCUMENT_ERR = ExceptionCode.WRONG_DOCUMENT_ERR = ((ExceptionMessage[4]=\\\"Wrong document\\\"),4);\\nvar INVALID_CHARACTER_ERR = ExceptionCode.INVALID_CHARACTER_ERR = ((ExceptionMessage[5]=\\\"Invalid character\\\"),5);\\nvar NO_DATA_ALLOWED_ERR = ExceptionCode.NO_DATA_ALLOWED_ERR = ((ExceptionMessage[6]=\\\"No data allowed\\\"),6);\\nvar NO_MODIFICATION_ALLOWED_ERR = ExceptionCode.NO_MODIFICATION_ALLOWED_ERR = ((ExceptionMessage[7]=\\\"No modification allowed\\\"),7);\\nvar NOT_FOUND_ERR = ExceptionCode.NOT_FOUND_ERR = ((ExceptionMessage[8]=\\\"Not found\\\"),8);\\nvar NOT_SUPPORTED_ERR = ExceptionCode.NOT_SUPPORTED_ERR = ((ExceptionMessage[9]=\\\"Not supported\\\"),9);\\nvar INUSE_ATTRIBUTE_ERR = ExceptionCode.INUSE_ATTRIBUTE_ERR = ((ExceptionMessage[10]=\\\"Attribute in use\\\"),10);\\n//level2\\nvar INVALID_STATE_ERR \\t= ExceptionCode.INVALID_STATE_ERR \\t= ((ExceptionMessage[11]=\\\"Invalid state\\\"),11);\\nvar SYNTAX_ERR \\t= ExceptionCode.SYNTAX_ERR \\t= ((ExceptionMessage[12]=\\\"Syntax error\\\"),12);\\nvar INVALID_MODIFICATION_ERR \\t= ExceptionCode.INVALID_MODIFICATION_ERR \\t= ((ExceptionMessage[13]=\\\"Invalid modification\\\"),13);\\nvar NAMESPACE_ERR \\t= ExceptionCode.NAMESPACE_ERR \\t= ((ExceptionMessage[14]=\\\"Invalid namespace\\\"),14);\\nvar INVALID_ACCESS_ERR \\t= ExceptionCode.INVALID_ACCESS_ERR \\t= ((ExceptionMessage[15]=\\\"Invalid access\\\"),15);\\n\\n\\nfunction DOMException(code, message) {\\n\\tif(message instanceof Error){\\n\\t\\tvar error = message;\\n\\t}else{\\n\\t\\terror = this;\\n\\t\\tError.call(this, ExceptionMessage[code]);\\n\\t\\tthis.message = ExceptionMessage[code];\\n\\t\\tif(Error.captureStackTrace) Error.captureStackTrace(this, DOMException);\\n\\t}\\n\\terror.code = code;\\n\\tif(message) this.message = this.message + \\\": \\\" + message;\\n\\treturn error;\\n};\\nDOMException.prototype = Error.prototype;\\ncopy(ExceptionCode,DOMException)\\n/**\\n * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-536297177\\n * The NodeList interface provides the abstraction of an ordered collection of nodes, without defining or constraining how this collection is implemented. NodeList objects in the DOM are live.\\n * The items in the NodeList are accessible via an integral index, starting from 0.\\n */\\nfunction NodeList() {\\n};\\nNodeList.prototype = {\\n\\t/**\\n\\t * The number of nodes in the list. The range of valid child node indices is 0 to length-1 inclusive.\\n\\t * @standard level1\\n\\t */\\n\\tlength:0, \\n\\t/**\\n\\t * Returns the indexth item in the collection. If index is greater than or equal to the number of nodes in the list, this returns null.\\n\\t * @standard level1\\n\\t * @param index unsigned long \\n\\t * Index into the collection.\\n\\t * @return Node\\n\\t * \\tThe node at the indexth position in the NodeList, or null if that is not a valid index. \\n\\t */\\n\\titem: function(index) {\\n\\t\\treturn this[index] || null;\\n\\t},\\n\\ttoString:function(isHTML,nodeFilter){\\n\\t\\tfor(var buf = [], i = 0;i<this.length;i++){\\n\\t\\t\\tserializeToString(this[i],buf,isHTML,nodeFilter);\\n\\t\\t}\\n\\t\\treturn buf.join('');\\n\\t}\\n};\\nfunction LiveNodeList(node,refresh){\\n\\tthis._node = node;\\n\\tthis._refresh = refresh\\n\\t_updateLiveList(this);\\n}\\nfunction _updateLiveList(list){\\n\\tvar inc = list._node._inc || list._node.ownerDocument._inc;\\n\\tif(list._inc != inc){\\n\\t\\tvar ls = list._refresh(list._node);\\n\\t\\t//console.log(ls.length)\\n\\t\\t__set__(list,'length',ls.length);\\n\\t\\tcopy(ls,list);\\n\\t\\tlist._inc = inc;\\n\\t}\\n}\\nLiveNodeList.prototype.item = function(i){\\n\\t_updateLiveList(this);\\n\\treturn this[i];\\n}\\n\\n_extends(LiveNodeList,NodeList);\\n/**\\n * \\n * Objects implementing the NamedNodeMap interface are used to represent collections of nodes that can be accessed by name. Note that NamedNodeMap does not inherit from NodeList; NamedNodeMaps are not maintained in any particular order. Objects contained in an object implementing NamedNodeMap may also be accessed by an ordinal index, but this is simply to allow convenient enumeration of the contents of a NamedNodeMap, and does not imply that the DOM specifies an order to these Nodes.\\n * NamedNodeMap objects in the DOM are live.\\n * used for attributes or DocumentType entities \\n */\\nfunction NamedNodeMap() {\\n};\\n\\nfunction _findNodeIndex(list,node){\\n\\tvar i = list.length;\\n\\twhile(i--){\\n\\t\\tif(list[i] === node){return i}\\n\\t}\\n}\\n\\nfunction _addNamedNode(el,list,newAttr,oldAttr){\\n\\tif(oldAttr){\\n\\t\\tlist[_findNodeIndex(list,oldAttr)] = newAttr;\\n\\t}else{\\n\\t\\tlist[list.length++] = newAttr;\\n\\t}\\n\\tif(el){\\n\\t\\tnewAttr.ownerElement = el;\\n\\t\\tvar doc = el.ownerDocument;\\n\\t\\tif(doc){\\n\\t\\t\\toldAttr && _onRemoveAttribute(doc,el,oldAttr);\\n\\t\\t\\t_onAddAttribute(doc,el,newAttr);\\n\\t\\t}\\n\\t}\\n}\\nfunction _removeNamedNode(el,list,attr){\\n\\t//console.log('remove attr:'+attr)\\n\\tvar i = _findNodeIndex(list,attr);\\n\\tif(i>=0){\\n\\t\\tvar lastIndex = list.length-1\\n\\t\\twhile(i<lastIndex){\\n\\t\\t\\tlist[i] = list[++i]\\n\\t\\t}\\n\\t\\tlist.length = lastIndex;\\n\\t\\tif(el){\\n\\t\\t\\tvar doc = el.ownerDocument;\\n\\t\\t\\tif(doc){\\n\\t\\t\\t\\t_onRemoveAttribute(doc,el,attr);\\n\\t\\t\\t\\tattr.ownerElement = null;\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}else{\\n\\t\\tthrow DOMException(NOT_FOUND_ERR,new Error(el.tagName+'@'+attr))\\n\\t}\\n}\\nNamedNodeMap.prototype = {\\n\\tlength:0,\\n\\titem:NodeList.prototype.item,\\n\\tgetNamedItem: function(key) {\\n//\\t\\tif(key.indexOf(':')>0 || key == 'xmlns'){\\n//\\t\\t\\treturn null;\\n//\\t\\t}\\n\\t\\t//console.log()\\n\\t\\tvar i = this.length;\\n\\t\\twhile(i--){\\n\\t\\t\\tvar attr = this[i];\\n\\t\\t\\t//console.log(attr.nodeName,key)\\n\\t\\t\\tif(attr.nodeName == key){\\n\\t\\t\\t\\treturn attr;\\n\\t\\t\\t}\\n\\t\\t}\\n\\t},\\n\\tsetNamedItem: function(attr) {\\n\\t\\tvar el = attr.ownerElement;\\n\\t\\tif(el && el!=this._ownerElement){\\n\\t\\t\\tthrow new DOMException(INUSE_ATTRIBUTE_ERR);\\n\\t\\t}\\n\\t\\tvar oldAttr = this.getNamedItem(attr.nodeName);\\n\\t\\t_addNamedNode(this._ownerElement,this,attr,oldAttr);\\n\\t\\treturn oldAttr;\\n\\t},\\n\\t/* returns Node */\\n\\tsetNamedItemNS: function(attr) {// raises: WRONG_DOCUMENT_ERR,NO_MODIFICATION_ALLOWED_ERR,INUSE_ATTRIBUTE_ERR\\n\\t\\tvar el = attr.ownerElement, oldAttr;\\n\\t\\tif(el && el!=this._ownerElement){\\n\\t\\t\\tthrow new DOMException(INUSE_ATTRIBUTE_ERR);\\n\\t\\t}\\n\\t\\toldAttr = this.getNamedItemNS(attr.namespaceURI,attr.localName);\\n\\t\\t_addNamedNode(this._ownerElement,this,attr,oldAttr);\\n\\t\\treturn oldAttr;\\n\\t},\\n\\n\\t/* returns Node */\\n\\tremoveNamedItem: function(key) {\\n\\t\\tvar attr = this.getNamedItem(key);\\n\\t\\t_removeNamedNode(this._ownerElement,this,attr);\\n\\t\\treturn attr;\\n\\t\\t\\n\\t\\t\\n\\t},// raises: NOT_FOUND_ERR,NO_MODIFICATION_ALLOWED_ERR\\n\\t\\n\\t//for level2\\n\\tremoveNamedItemNS:function(namespaceURI,localName){\\n\\t\\tvar attr = this.getNamedItemNS(namespaceURI,localName);\\n\\t\\t_removeNamedNode(this._ownerElement,this,attr);\\n\\t\\treturn attr;\\n\\t},\\n\\tgetNamedItemNS: function(namespaceURI, localName) {\\n\\t\\tvar i = this.length;\\n\\t\\twhile(i--){\\n\\t\\t\\tvar node = this[i];\\n\\t\\t\\tif(node.localName == localName && node.namespaceURI == namespaceURI){\\n\\t\\t\\t\\treturn node;\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\treturn null;\\n\\t}\\n};\\n/**\\n * @see http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-102161490\\n */\\nfunction DOMImplementation(/* Object */ features) {\\n\\tthis._features = {};\\n\\tif (features) {\\n\\t\\tfor (var feature in features) {\\n\\t\\t\\t this._features = features[feature];\\n\\t\\t}\\n\\t}\\n};\\n\\nDOMImplementation.prototype = {\\n\\thasFeature: function(/* string */ feature, /* string */ version) {\\n\\t\\tvar versions = this._features[feature.toLowerCase()];\\n\\t\\tif (versions && (!version || version in versions)) {\\n\\t\\t\\treturn true;\\n\\t\\t} else {\\n\\t\\t\\treturn false;\\n\\t\\t}\\n\\t},\\n\\t// Introduced in DOM Level 2:\\n\\tcreateDocument:function(namespaceURI, qualifiedName, doctype){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR,WRONG_DOCUMENT_ERR\\n\\t\\tvar doc = new Document();\\n\\t\\tdoc.implementation = this;\\n\\t\\tdoc.childNodes = new NodeList();\\n\\t\\tdoc.doctype = doctype;\\n\\t\\tif(doctype){\\n\\t\\t\\tdoc.appendChild(doctype);\\n\\t\\t}\\n\\t\\tif(qualifiedName){\\n\\t\\t\\tvar root = doc.createElementNS(namespaceURI,qualifiedName);\\n\\t\\t\\tdoc.appendChild(root);\\n\\t\\t}\\n\\t\\treturn doc;\\n\\t},\\n\\t// Introduced in DOM Level 2:\\n\\tcreateDocumentType:function(qualifiedName, publicId, systemId){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR\\n\\t\\tvar node = new DocumentType();\\n\\t\\tnode.name = qualifiedName;\\n\\t\\tnode.nodeName = qualifiedName;\\n\\t\\tnode.publicId = publicId;\\n\\t\\tnode.systemId = systemId;\\n\\t\\t// Introduced in DOM Level 2:\\n\\t\\t//readonly attribute DOMString internalSubset;\\n\\t\\t\\n\\t\\t//TODO:..\\n\\t\\t// readonly attribute NamedNodeMap entities;\\n\\t\\t// readonly attribute NamedNodeMap notations;\\n\\t\\treturn node;\\n\\t}\\n};\\n\\n\\n/**\\n * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247\\n */\\n\\nfunction Node() {\\n};\\n\\nNode.prototype = {\\n\\tfirstChild : null,\\n\\tlastChild : null,\\n\\tpreviousSibling : null,\\n\\tnextSibling : null,\\n\\tattributes : null,\\n\\tparentNode : null,\\n\\tchildNodes : null,\\n\\townerDocument : null,\\n\\tnodeValue : null,\\n\\tnamespaceURI : null,\\n\\tprefix : null,\\n\\tlocalName : null,\\n\\t// Modified in DOM Level 2:\\n\\tinsertBefore:function(newChild, refChild){//raises \\n\\t\\treturn _insertBefore(this,newChild,refChild);\\n\\t},\\n\\treplaceChild:function(newChild, oldChild){//raises \\n\\t\\tthis.insertBefore(newChild,oldChild);\\n\\t\\tif(oldChild){\\n\\t\\t\\tthis.removeChild(oldChild);\\n\\t\\t}\\n\\t},\\n\\tremoveChild:function(oldChild){\\n\\t\\treturn _removeChild(this,oldChild);\\n\\t},\\n\\tappendChild:function(newChild){\\n\\t\\treturn this.insertBefore(newChild,null);\\n\\t},\\n\\thasChildNodes:function(){\\n\\t\\treturn this.firstChild != null;\\n\\t},\\n\\tcloneNode:function(deep){\\n\\t\\treturn cloneNode(this.ownerDocument||this,this,deep);\\n\\t},\\n\\t// Modified in DOM Level 2:\\n\\tnormalize:function(){\\n\\t\\tvar child = this.firstChild;\\n\\t\\twhile(child){\\n\\t\\t\\tvar next = child.nextSibling;\\n\\t\\t\\tif(next && next.nodeType == TEXT_NODE && child.nodeType == TEXT_NODE){\\n\\t\\t\\t\\tthis.removeChild(next);\\n\\t\\t\\t\\tchild.appendData(next.data);\\n\\t\\t\\t}else{\\n\\t\\t\\t\\tchild.normalize();\\n\\t\\t\\t\\tchild = next;\\n\\t\\t\\t}\\n\\t\\t}\\n\\t},\\n \\t// Introduced in DOM Level 2:\\n\\tisSupported:function(feature, version){\\n\\t\\treturn this.ownerDocument.implementation.hasFeature(feature,version);\\n\\t},\\n // Introduced in DOM Level 2:\\n hasAttributes:function(){\\n \\treturn this.attributes.length>0;\\n },\\n lookupPrefix:function(namespaceURI){\\n \\tvar el = this;\\n \\twhile(el){\\n \\t\\tvar map = el._nsMap;\\n \\t\\t//console.dir(map)\\n \\t\\tif(map){\\n \\t\\t\\tfor(var n in map){\\n \\t\\t\\t\\tif(map[n] == namespaceURI){\\n \\t\\t\\t\\t\\treturn n;\\n \\t\\t\\t\\t}\\n \\t\\t\\t}\\n \\t\\t}\\n \\t\\tel = el.nodeType == ATTRIBUTE_NODE?el.ownerDocument : el.parentNode;\\n \\t}\\n \\treturn null;\\n },\\n // Introduced in DOM Level 3:\\n lookupNamespaceURI:function(prefix){\\n \\tvar el = this;\\n \\twhile(el){\\n \\t\\tvar map = el._nsMap;\\n \\t\\t//console.dir(map)\\n \\t\\tif(map){\\n \\t\\t\\tif(prefix in map){\\n \\t\\t\\t\\treturn map[prefix] ;\\n \\t\\t\\t}\\n \\t\\t}\\n \\t\\tel = el.nodeType == ATTRIBUTE_NODE?el.ownerDocument : el.parentNode;\\n \\t}\\n \\treturn null;\\n },\\n // Introduced in DOM Level 3:\\n isDefaultNamespace:function(namespaceURI){\\n \\tvar prefix = this.lookupPrefix(namespaceURI);\\n \\treturn prefix == null;\\n }\\n};\\n\\n\\nfunction _xmlEncoder(c){\\n\\treturn c == '<' && '<' ||\\n c == '>' && '>' ||\\n c == '&' && '&' ||\\n c == '\\\"' && '"' ||\\n '&#'+c.charCodeAt()+';'\\n}\\n\\n\\ncopy(NodeType,Node);\\ncopy(NodeType,Node.prototype);\\n\\n/**\\n * @param callback return true for continue,false for break\\n * @return boolean true: break visit;\\n */\\nfunction _visitNode(node,callback){\\n\\tif(callback(node)){\\n\\t\\treturn true;\\n\\t}\\n\\tif(node = node.firstChild){\\n\\t\\tdo{\\n\\t\\t\\tif(_visitNode(node,callback)){return true}\\n }while(node=node.nextSibling)\\n }\\n}\\n\\n\\n\\nfunction Document(){\\n}\\nfunction _onAddAttribute(doc,el,newAttr){\\n\\tdoc && doc._inc++;\\n\\tvar ns = newAttr.namespaceURI ;\\n\\tif(ns == 'http://www.w3.org/2000/xmlns/'){\\n\\t\\t//update namespace\\n\\t\\tel._nsMap[newAttr.prefix?newAttr.localName:''] = newAttr.value\\n\\t}\\n}\\nfunction _onRemoveAttribute(doc,el,newAttr,remove){\\n\\tdoc && doc._inc++;\\n\\tvar ns = newAttr.namespaceURI ;\\n\\tif(ns == 'http://www.w3.org/2000/xmlns/'){\\n\\t\\t//update namespace\\n\\t\\tdelete el._nsMap[newAttr.prefix?newAttr.localName:'']\\n\\t}\\n}\\nfunction _onUpdateChild(doc,el,newChild){\\n\\tif(doc && doc._inc){\\n\\t\\tdoc._inc++;\\n\\t\\t//update childNodes\\n\\t\\tvar cs = el.childNodes;\\n\\t\\tif(newChild){\\n\\t\\t\\tcs[cs.length++] = newChild;\\n\\t\\t}else{\\n\\t\\t\\t//console.log(1)\\n\\t\\t\\tvar child = el.firstChild;\\n\\t\\t\\tvar i = 0;\\n\\t\\t\\twhile(child){\\n\\t\\t\\t\\tcs[i++] = child;\\n\\t\\t\\t\\tchild =child.nextSibling;\\n\\t\\t\\t}\\n\\t\\t\\tcs.length = i;\\n\\t\\t}\\n\\t}\\n}\\n\\n/**\\n * attributes;\\n * children;\\n * \\n * writeable properties:\\n * nodeValue,Attr:value,CharacterData:data\\n * prefix\\n */\\nfunction _removeChild(parentNode,child){\\n\\tvar previous = child.previousSibling;\\n\\tvar next = child.nextSibling;\\n\\tif(previous){\\n\\t\\tprevious.nextSibling = next;\\n\\t}else{\\n\\t\\tparentNode.firstChild = next\\n\\t}\\n\\tif(next){\\n\\t\\tnext.previousSibling = previous;\\n\\t}else{\\n\\t\\tparentNode.lastChild = previous;\\n\\t}\\n\\t_onUpdateChild(parentNode.ownerDocument,parentNode);\\n\\treturn child;\\n}\\n/**\\n * preformance key(refChild == null)\\n */\\nfunction _insertBefore(parentNode,newChild,nextChild){\\n\\tvar cp = newChild.parentNode;\\n\\tif(cp){\\n\\t\\tcp.removeChild(newChild);//remove and update\\n\\t}\\n\\tif(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){\\n\\t\\tvar newFirst = newChild.firstChild;\\n\\t\\tif (newFirst == null) {\\n\\t\\t\\treturn newChild;\\n\\t\\t}\\n\\t\\tvar newLast = newChild.lastChild;\\n\\t}else{\\n\\t\\tnewFirst = newLast = newChild;\\n\\t}\\n\\tvar pre = nextChild ? nextChild.previousSibling : parentNode.lastChild;\\n\\n\\tnewFirst.previousSibling = pre;\\n\\tnewLast.nextSibling = nextChild;\\n\\t\\n\\t\\n\\tif(pre){\\n\\t\\tpre.nextSibling = newFirst;\\n\\t}else{\\n\\t\\tparentNode.firstChild = newFirst;\\n\\t}\\n\\tif(nextChild == null){\\n\\t\\tparentNode.lastChild = newLast;\\n\\t}else{\\n\\t\\tnextChild.previousSibling = newLast;\\n\\t}\\n\\tdo{\\n\\t\\tnewFirst.parentNode = parentNode;\\n\\t}while(newFirst !== newLast && (newFirst= newFirst.nextSibling))\\n\\t_onUpdateChild(parentNode.ownerDocument||parentNode,parentNode);\\n\\t//console.log(parentNode.lastChild.nextSibling == null)\\n\\tif (newChild.nodeType == DOCUMENT_FRAGMENT_NODE) {\\n\\t\\tnewChild.firstChild = newChild.lastChild = null;\\n\\t}\\n\\treturn newChild;\\n}\\nfunction _appendSingleChild(parentNode,newChild){\\n\\tvar cp = newChild.parentNode;\\n\\tif(cp){\\n\\t\\tvar pre = parentNode.lastChild;\\n\\t\\tcp.removeChild(newChild);//remove and update\\n\\t\\tvar pre = parentNode.lastChild;\\n\\t}\\n\\tvar pre = parentNode.lastChild;\\n\\tnewChild.parentNode = parentNode;\\n\\tnewChild.previousSibling = pre;\\n\\tnewChild.nextSibling = null;\\n\\tif(pre){\\n\\t\\tpre.nextSibling = newChild;\\n\\t}else{\\n\\t\\tparentNode.firstChild = newChild;\\n\\t}\\n\\tparentNode.lastChild = newChild;\\n\\t_onUpdateChild(parentNode.ownerDocument,parentNode,newChild);\\n\\treturn newChild;\\n\\t//console.log(\\\"__aa\\\",parentNode.lastChild.nextSibling == null)\\n}\\nDocument.prototype = {\\n\\t//implementation : null,\\n\\tnodeName : '#document',\\n\\tnodeType : DOCUMENT_NODE,\\n\\tdoctype : null,\\n\\tdocumentElement : null,\\n\\t_inc : 1,\\n\\t\\n\\tinsertBefore : function(newChild, refChild){//raises \\n\\t\\tif(newChild.nodeType == DOCUMENT_FRAGMENT_NODE){\\n\\t\\t\\tvar child = newChild.firstChild;\\n\\t\\t\\twhile(child){\\n\\t\\t\\t\\tvar next = child.nextSibling;\\n\\t\\t\\t\\tthis.insertBefore(child,refChild);\\n\\t\\t\\t\\tchild = next;\\n\\t\\t\\t}\\n\\t\\t\\treturn newChild;\\n\\t\\t}\\n\\t\\tif(this.documentElement == null && newChild.nodeType == ELEMENT_NODE){\\n\\t\\t\\tthis.documentElement = newChild;\\n\\t\\t}\\n\\t\\t\\n\\t\\treturn _insertBefore(this,newChild,refChild),(newChild.ownerDocument = this),newChild;\\n\\t},\\n\\tremoveChild : function(oldChild){\\n\\t\\tif(this.documentElement == oldChild){\\n\\t\\t\\tthis.documentElement = null;\\n\\t\\t}\\n\\t\\treturn _removeChild(this,oldChild);\\n\\t},\\n\\t// Introduced in DOM Level 2:\\n\\timportNode : function(importedNode,deep){\\n\\t\\treturn importNode(this,importedNode,deep);\\n\\t},\\n\\t// Introduced in DOM Level 2:\\n\\tgetElementById :\\tfunction(id){\\n\\t\\tvar rtv = null;\\n\\t\\t_visitNode(this.documentElement,function(node){\\n\\t\\t\\tif(node.nodeType == ELEMENT_NODE){\\n\\t\\t\\t\\tif(node.getAttribute('id') == id){\\n\\t\\t\\t\\t\\trtv = node;\\n\\t\\t\\t\\t\\treturn true;\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t})\\n\\t\\treturn rtv;\\n\\t},\\n\\t\\n\\t//document factory method:\\n\\tcreateElement :\\tfunction(tagName){\\n\\t\\tvar node = new Element();\\n\\t\\tnode.ownerDocument = this;\\n\\t\\tnode.nodeName = tagName;\\n\\t\\tnode.tagName = tagName;\\n\\t\\tnode.childNodes = new NodeList();\\n\\t\\tvar attrs\\t= node.attributes = new NamedNodeMap();\\n\\t\\tattrs._ownerElement = node;\\n\\t\\treturn node;\\n\\t},\\n\\tcreateDocumentFragment :\\tfunction(){\\n\\t\\tvar node = new DocumentFragment();\\n\\t\\tnode.ownerDocument = this;\\n\\t\\tnode.childNodes = new NodeList();\\n\\t\\treturn node;\\n\\t},\\n\\tcreateTextNode :\\tfunction(data){\\n\\t\\tvar node = new Text();\\n\\t\\tnode.ownerDocument = this;\\n\\t\\tnode.appendData(data)\\n\\t\\treturn node;\\n\\t},\\n\\tcreateComment :\\tfunction(data){\\n\\t\\tvar node = new Comment();\\n\\t\\tnode.ownerDocument = this;\\n\\t\\tnode.appendData(data)\\n\\t\\treturn node;\\n\\t},\\n\\tcreateCDATASection :\\tfunction(data){\\n\\t\\tvar node = new CDATASection();\\n\\t\\tnode.ownerDocument = this;\\n\\t\\tnode.appendData(data)\\n\\t\\treturn node;\\n\\t},\\n\\tcreateProcessingInstruction :\\tfunction(target,data){\\n\\t\\tvar node = new ProcessingInstruction();\\n\\t\\tnode.ownerDocument = this;\\n\\t\\tnode.tagName = node.target = target;\\n\\t\\tnode.nodeValue= node.data = data;\\n\\t\\treturn node;\\n\\t},\\n\\tcreateAttribute :\\tfunction(name){\\n\\t\\tvar node = new Attr();\\n\\t\\tnode.ownerDocument\\t= this;\\n\\t\\tnode.name = name;\\n\\t\\tnode.nodeName\\t= name;\\n\\t\\tnode.localName = name;\\n\\t\\tnode.specified = true;\\n\\t\\treturn node;\\n\\t},\\n\\tcreateEntityReference :\\tfunction(name){\\n\\t\\tvar node = new EntityReference();\\n\\t\\tnode.ownerDocument\\t= this;\\n\\t\\tnode.nodeName\\t= name;\\n\\t\\treturn node;\\n\\t},\\n\\t// Introduced in DOM Level 2:\\n\\tcreateElementNS :\\tfunction(namespaceURI,qualifiedName){\\n\\t\\tvar node = new Element();\\n\\t\\tvar pl = qualifiedName.split(':');\\n\\t\\tvar attrs\\t= node.attributes = new NamedNodeMap();\\n\\t\\tnode.childNodes = new NodeList();\\n\\t\\tnode.ownerDocument = this;\\n\\t\\tnode.nodeName = qualifiedName;\\n\\t\\tnode.tagName = qualifiedName;\\n\\t\\tnode.namespaceURI = namespaceURI;\\n\\t\\tif(pl.length == 2){\\n\\t\\t\\tnode.prefix = pl[0];\\n\\t\\t\\tnode.localName = pl[1];\\n\\t\\t}else{\\n\\t\\t\\t//el.prefix = null;\\n\\t\\t\\tnode.localName = qualifiedName;\\n\\t\\t}\\n\\t\\tattrs._ownerElement = node;\\n\\t\\treturn node;\\n\\t},\\n\\t// Introduced in DOM Level 2:\\n\\tcreateAttributeNS :\\tfunction(namespaceURI,qualifiedName){\\n\\t\\tvar node = new Attr();\\n\\t\\tvar pl = qualifiedName.split(':');\\n\\t\\tnode.ownerDocument = this;\\n\\t\\tnode.nodeName = qualifiedName;\\n\\t\\tnode.name = qualifiedName;\\n\\t\\tnode.namespaceURI = namespaceURI;\\n\\t\\tnode.specified = true;\\n\\t\\tif(pl.length == 2){\\n\\t\\t\\tnode.prefix = pl[0];\\n\\t\\t\\tnode.localName = pl[1];\\n\\t\\t}else{\\n\\t\\t\\t//el.prefix = null;\\n\\t\\t\\tnode.localName = qualifiedName;\\n\\t\\t}\\n\\t\\treturn node;\\n\\t}\\n};\\n_extends(Document,Node);\\n\\n\\nfunction Element() {\\n\\tthis._nsMap = {};\\n};\\nElement.prototype = {\\n\\tnodeType : ELEMENT_NODE,\\n\\thasAttribute : function(name){\\n\\t\\treturn this.getAttributeNode(name)!=null;\\n\\t},\\n\\tgetAttribute : function(name){\\n\\t\\tvar attr = this.getAttributeNode(name);\\n\\t\\treturn attr && attr.value || '';\\n\\t},\\n\\tgetAttributeNode : function(name){\\n\\t\\treturn this.attributes.getNamedItem(name);\\n\\t},\\n\\tsetAttribute : function(name, value){\\n\\t\\tvar attr = this.ownerDocument.createAttribute(name);\\n\\t\\tattr.value = attr.nodeValue = \\\"\\\" + value;\\n\\t\\tthis.setAttributeNode(attr)\\n\\t},\\n\\tremoveAttribute : function(name){\\n\\t\\tvar attr = this.getAttributeNode(name)\\n\\t\\tattr && this.removeAttributeNode(attr);\\n\\t},\\n\\t\\n\\t//four real opeartion method\\n\\tappendChild:function(newChild){\\n\\t\\tif(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){\\n\\t\\t\\treturn this.insertBefore(newChild,null);\\n\\t\\t}else{\\n\\t\\t\\treturn _appendSingleChild(this,newChild);\\n\\t\\t}\\n\\t},\\n\\tsetAttributeNode : function(newAttr){\\n\\t\\treturn this.attributes.setNamedItem(newAttr);\\n\\t},\\n\\tsetAttributeNodeNS : function(newAttr){\\n\\t\\treturn this.attributes.setNamedItemNS(newAttr);\\n\\t},\\n\\tremoveAttributeNode : function(oldAttr){\\n\\t\\t//console.log(this == oldAttr.ownerElement)\\n\\t\\treturn this.attributes.removeNamedItem(oldAttr.nodeName);\\n\\t},\\n\\t//get real attribute name,and remove it by removeAttributeNode\\n\\tremoveAttributeNS : function(namespaceURI, localName){\\n\\t\\tvar old = this.getAttributeNodeNS(namespaceURI, localName);\\n\\t\\told && this.removeAttributeNode(old);\\n\\t},\\n\\t\\n\\thasAttributeNS : function(namespaceURI, localName){\\n\\t\\treturn this.getAttributeNodeNS(namespaceURI, localName)!=null;\\n\\t},\\n\\tgetAttributeNS : function(namespaceURI, localName){\\n\\t\\tvar attr = this.getAttributeNodeNS(namespaceURI, localName);\\n\\t\\treturn attr && attr.value || '';\\n\\t},\\n\\tsetAttributeNS : function(namespaceURI, qualifiedName, value){\\n\\t\\tvar attr = this.ownerDocument.createAttributeNS(namespaceURI, qualifiedName);\\n\\t\\tattr.value = attr.nodeValue = \\\"\\\" + value;\\n\\t\\tthis.setAttributeNode(attr)\\n\\t},\\n\\tgetAttributeNodeNS : function(namespaceURI, localName){\\n\\t\\treturn this.attributes.getNamedItemNS(namespaceURI, localName);\\n\\t},\\n\\t\\n\\tgetElementsByTagName : function(tagName){\\n\\t\\treturn new LiveNodeList(this,function(base){\\n\\t\\t\\tvar ls = [];\\n\\t\\t\\t_visitNode(base,function(node){\\n\\t\\t\\t\\tif(node !== base && node.nodeType == ELEMENT_NODE && (tagName === '*' || node.tagName == tagName)){\\n\\t\\t\\t\\t\\tls.push(node);\\n\\t\\t\\t\\t}\\n\\t\\t\\t});\\n\\t\\t\\treturn ls;\\n\\t\\t});\\n\\t},\\n\\tgetElementsByTagNameNS : function(namespaceURI, localName){\\n\\t\\treturn new LiveNodeList(this,function(base){\\n\\t\\t\\tvar ls = [];\\n\\t\\t\\t_visitNode(base,function(node){\\n\\t\\t\\t\\tif(node !== base && node.nodeType === ELEMENT_NODE && (namespaceURI === '*' || node.namespaceURI === namespaceURI) && (localName === '*' || node.localName == localName)){\\n\\t\\t\\t\\t\\tls.push(node);\\n\\t\\t\\t\\t}\\n\\t\\t\\t});\\n\\t\\t\\treturn ls;\\n\\t\\t\\t\\n\\t\\t});\\n\\t}\\n};\\nDocument.prototype.getElementsByTagName = Element.prototype.getElementsByTagName;\\nDocument.prototype.getElementsByTagNameNS = Element.prototype.getElementsByTagNameNS;\\n\\n\\n_extends(Element,Node);\\nfunction Attr() {\\n};\\nAttr.prototype.nodeType = ATTRIBUTE_NODE;\\n_extends(Attr,Node);\\n\\n\\nfunction CharacterData() {\\n};\\nCharacterData.prototype = {\\n\\tdata : '',\\n\\tsubstringData : function(offset, count) {\\n\\t\\treturn this.data.substring(offset, offset+count);\\n\\t},\\n\\tappendData: function(text) {\\n\\t\\ttext = this.data+text;\\n\\t\\tthis.nodeValue = this.data = text;\\n\\t\\tthis.length = text.length;\\n\\t},\\n\\tinsertData: function(offset,text) {\\n\\t\\tthis.replaceData(offset,0,text);\\n\\t\\n\\t},\\n\\tappendChild:function(newChild){\\n\\t\\tthrow new Error(ExceptionMessage[HIERARCHY_REQUEST_ERR])\\n\\t},\\n\\tdeleteData: function(offset, count) {\\n\\t\\tthis.replaceData(offset,count,\\\"\\\");\\n\\t},\\n\\treplaceData: function(offset, count, text) {\\n\\t\\tvar start = this.data.substring(0,offset);\\n\\t\\tvar end = this.data.substring(offset+count);\\n\\t\\ttext = start + text + end;\\n\\t\\tthis.nodeValue = this.data = text;\\n\\t\\tthis.length = text.length;\\n\\t}\\n}\\n_extends(CharacterData,Node);\\nfunction Text() {\\n};\\nText.prototype = {\\n\\tnodeName : \\\"#text\\\",\\n\\tnodeType : TEXT_NODE,\\n\\tsplitText : function(offset) {\\n\\t\\tvar text = this.data;\\n\\t\\tvar newText = text.substring(offset);\\n\\t\\ttext = text.substring(0, offset);\\n\\t\\tthis.data = this.nodeValue = text;\\n\\t\\tthis.length = text.length;\\n\\t\\tvar newNode = this.ownerDocument.createTextNode(newText);\\n\\t\\tif(this.parentNode){\\n\\t\\t\\tthis.parentNode.insertBefore(newNode, this.nextSibling);\\n\\t\\t}\\n\\t\\treturn newNode;\\n\\t}\\n}\\n_extends(Text,CharacterData);\\nfunction Comment() {\\n};\\nComment.prototype = {\\n\\tnodeName : \\\"#comment\\\",\\n\\tnodeType : COMMENT_NODE\\n}\\n_extends(Comment,CharacterData);\\n\\nfunction CDATASection() {\\n};\\nCDATASection.prototype = {\\n\\tnodeName : \\\"#cdata-section\\\",\\n\\tnodeType : CDATA_SECTION_NODE\\n}\\n_extends(CDATASection,CharacterData);\\n\\n\\nfunction DocumentType() {\\n};\\nDocumentType.prototype.nodeType = DOCUMENT_TYPE_NODE;\\n_extends(DocumentType,Node);\\n\\nfunction Notation() {\\n};\\nNotation.prototype.nodeType = NOTATION_NODE;\\n_extends(Notation,Node);\\n\\nfunction Entity() {\\n};\\nEntity.prototype.nodeType = ENTITY_NODE;\\n_extends(Entity,Node);\\n\\nfunction EntityReference() {\\n};\\nEntityReference.prototype.nodeType = ENTITY_REFERENCE_NODE;\\n_extends(EntityReference,Node);\\n\\nfunction DocumentFragment() {\\n};\\nDocumentFragment.prototype.nodeName =\\t\\\"#document-fragment\\\";\\nDocumentFragment.prototype.nodeType =\\tDOCUMENT_FRAGMENT_NODE;\\n_extends(DocumentFragment,Node);\\n\\n\\nfunction ProcessingInstruction() {\\n}\\nProcessingInstruction.prototype.nodeType = PROCESSING_INSTRUCTION_NODE;\\n_extends(ProcessingInstruction,Node);\\nfunction XMLSerializer(){}\\nXMLSerializer.prototype.serializeToString = function(node,isHtml,nodeFilter){\\n\\treturn nodeSerializeToString.call(node,isHtml,nodeFilter);\\n}\\nNode.prototype.toString = nodeSerializeToString;\\nfunction nodeSerializeToString(isHtml,nodeFilter){\\n\\tvar buf = [];\\n\\tvar refNode = this.nodeType == 9 && this.documentElement || this;\\n\\tvar prefix = refNode.prefix;\\n\\tvar uri = refNode.namespaceURI;\\n\\t\\n\\tif(uri && prefix == null){\\n\\t\\t//console.log(prefix)\\n\\t\\tvar prefix = refNode.lookupPrefix(uri);\\n\\t\\tif(prefix == null){\\n\\t\\t\\t//isHTML = true;\\n\\t\\t\\tvar visibleNamespaces=[\\n\\t\\t\\t{namespace:uri,prefix:null}\\n\\t\\t\\t//{namespace:uri,prefix:''}\\n\\t\\t\\t]\\n\\t\\t}\\n\\t}\\n\\tserializeToString(this,buf,isHtml,nodeFilter,visibleNamespaces);\\n\\t//console.log('###',this.nodeType,uri,prefix,buf.join(''))\\n\\treturn buf.join('');\\n}\\nfunction needNamespaceDefine(node,isHTML, visibleNamespaces) {\\n\\tvar prefix = node.prefix||'';\\n\\tvar uri = node.namespaceURI;\\n\\tif (!prefix && !uri){\\n\\t\\treturn false;\\n\\t}\\n\\tif (prefix === \\\"xml\\\" && uri === \\\"http://www.w3.org/XML/1998/namespace\\\" \\n\\t\\t|| uri == 'http://www.w3.org/2000/xmlns/'){\\n\\t\\treturn false;\\n\\t}\\n\\t\\n\\tvar i = visibleNamespaces.length \\n\\t//console.log('@@@@',node.tagName,prefix,uri,visibleNamespaces)\\n\\twhile (i--) {\\n\\t\\tvar ns = visibleNamespaces[i];\\n\\t\\t// get namespace prefix\\n\\t\\t//console.log(node.nodeType,node.tagName,ns.prefix,prefix)\\n\\t\\tif (ns.prefix == prefix){\\n\\t\\t\\treturn ns.namespace != uri;\\n\\t\\t}\\n\\t}\\n\\t//console.log(isHTML,uri,prefix=='')\\n\\t//if(isHTML && prefix ==null && uri == 'http://www.w3.org/1999/xhtml'){\\n\\t//\\treturn false;\\n\\t//}\\n\\t//node.flag = '11111'\\n\\t//console.error(3,true,node.flag,node.prefix,node.namespaceURI)\\n\\treturn true;\\n}\\nfunction serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){\\n\\tif(nodeFilter){\\n\\t\\tnode = nodeFilter(node);\\n\\t\\tif(node){\\n\\t\\t\\tif(typeof node == 'string'){\\n\\t\\t\\t\\tbuf.push(node);\\n\\t\\t\\t\\treturn;\\n\\t\\t\\t}\\n\\t\\t}else{\\n\\t\\t\\treturn;\\n\\t\\t}\\n\\t\\t//buf.sort.apply(attrs, attributeSorter);\\n\\t}\\n\\tswitch(node.nodeType){\\n\\tcase ELEMENT_NODE:\\n\\t\\tif (!visibleNamespaces) visibleNamespaces = [];\\n\\t\\tvar startVisibleNamespaces = visibleNamespaces.length;\\n\\t\\tvar attrs = node.attributes;\\n\\t\\tvar len = attrs.length;\\n\\t\\tvar child = node.firstChild;\\n\\t\\tvar nodeName = node.tagName;\\n\\t\\t\\n\\t\\tisHTML = (htmlns === node.namespaceURI) ||isHTML \\n\\t\\tbuf.push('<',nodeName);\\n\\t\\t\\n\\t\\t\\n\\t\\t\\n\\t\\tfor(var i=0;i<len;i++){\\n\\t\\t\\t// add namespaces for attributes\\n\\t\\t\\tvar attr = attrs.item(i);\\n\\t\\t\\tif (attr.prefix == 'xmlns') {\\n\\t\\t\\t\\tvisibleNamespaces.push({ prefix: attr.localName, namespace: attr.value });\\n\\t\\t\\t}else if(attr.nodeName == 'xmlns'){\\n\\t\\t\\t\\tvisibleNamespaces.push({ prefix: '', namespace: attr.value });\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\tfor(var i=0;i<len;i++){\\n\\t\\t\\tvar attr = attrs.item(i);\\n\\t\\t\\tif (needNamespaceDefine(attr,isHTML, visibleNamespaces)) {\\n\\t\\t\\t\\tvar prefix = attr.prefix||'';\\n\\t\\t\\t\\tvar uri = attr.namespaceURI;\\n\\t\\t\\t\\tvar ns = prefix ? ' xmlns:' + prefix : \\\" xmlns\\\";\\n\\t\\t\\t\\tbuf.push(ns, '=\\\"' , uri , '\\\"');\\n\\t\\t\\t\\tvisibleNamespaces.push({ prefix: prefix, namespace:uri });\\n\\t\\t\\t}\\n\\t\\t\\tserializeToString(attr,buf,isHTML,nodeFilter,visibleNamespaces);\\n\\t\\t}\\n\\t\\t// add namespace for current node\\t\\t\\n\\t\\tif (needNamespaceDefine(node,isHTML, visibleNamespaces)) {\\n\\t\\t\\tvar prefix = node.prefix||'';\\n\\t\\t\\tvar uri = node.namespaceURI;\\n\\t\\t\\tvar ns = prefix ? ' xmlns:' + prefix : \\\" xmlns\\\";\\n\\t\\t\\tbuf.push(ns, '=\\\"' , uri , '\\\"');\\n\\t\\t\\tvisibleNamespaces.push({ prefix: prefix, namespace:uri });\\n\\t\\t}\\n\\t\\t\\n\\t\\tif(child || isHTML && !/^(?:meta|link|img|br|hr|input)$/i.test(nodeName)){\\n\\t\\t\\tbuf.push('>');\\n\\t\\t\\t//if is cdata child node\\n\\t\\t\\tif(isHTML && /^script$/i.test(nodeName)){\\n\\t\\t\\t\\twhile(child){\\n\\t\\t\\t\\t\\tif(child.data){\\n\\t\\t\\t\\t\\t\\tbuf.push(child.data);\\n\\t\\t\\t\\t\\t}else{\\n\\t\\t\\t\\t\\t\\tserializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);\\n\\t\\t\\t\\t\\t}\\n\\t\\t\\t\\t\\tchild = child.nextSibling;\\n\\t\\t\\t\\t}\\n\\t\\t\\t}else\\n\\t\\t\\t{\\n\\t\\t\\t\\twhile(child){\\n\\t\\t\\t\\t\\tserializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);\\n\\t\\t\\t\\t\\tchild = child.nextSibling;\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t\\tbuf.push('</',nodeName,'>');\\n\\t\\t}else{\\n\\t\\t\\tbuf.push('/>');\\n\\t\\t}\\n\\t\\t// remove added visible namespaces\\n\\t\\t//visibleNamespaces.length = startVisibleNamespaces;\\n\\t\\treturn;\\n\\tcase DOCUMENT_NODE:\\n\\tcase DOCUMENT_FRAGMENT_NODE:\\n\\t\\tvar child = node.firstChild;\\n\\t\\twhile(child){\\n\\t\\t\\tserializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);\\n\\t\\t\\tchild = child.nextSibling;\\n\\t\\t}\\n\\t\\treturn;\\n\\tcase ATTRIBUTE_NODE:\\n\\t\\treturn buf.push(' ',node.name,'=\\\"',node.value.replace(/[<&\\\"]/g,_xmlEncoder),'\\\"');\\n\\tcase TEXT_NODE:\\n\\t\\treturn buf.push(node.data.replace(/[<&]/g,_xmlEncoder));\\n\\tcase CDATA_SECTION_NODE:\\n\\t\\treturn buf.push( '<![CDATA[',node.data,']]>');\\n\\tcase COMMENT_NODE:\\n\\t\\treturn buf.push( \\\"<!--\\\",node.data,\\\"-->\\\");\\n\\tcase DOCUMENT_TYPE_NODE:\\n\\t\\tvar pubid = node.publicId;\\n\\t\\tvar sysid = node.systemId;\\n\\t\\tbuf.push('<!DOCTYPE ',node.name);\\n\\t\\tif(pubid){\\n\\t\\t\\tbuf.push(' PUBLIC \\\"',pubid);\\n\\t\\t\\tif (sysid && sysid!='.') {\\n\\t\\t\\t\\tbuf.push( '\\\" \\\"',sysid);\\n\\t\\t\\t}\\n\\t\\t\\tbuf.push('\\\">');\\n\\t\\t}else if(sysid && sysid!='.'){\\n\\t\\t\\tbuf.push(' SYSTEM \\\"',sysid,'\\\">');\\n\\t\\t}else{\\n\\t\\t\\tvar sub = node.internalSubset;\\n\\t\\t\\tif(sub){\\n\\t\\t\\t\\tbuf.push(\\\" [\\\",sub,\\\"]\\\");\\n\\t\\t\\t}\\n\\t\\t\\tbuf.push(\\\">\\\");\\n\\t\\t}\\n\\t\\treturn;\\n\\tcase PROCESSING_INSTRUCTION_NODE:\\n\\t\\treturn buf.push( \\\"<?\\\",node.target,\\\" \\\",node.data,\\\"?>\\\");\\n\\tcase ENTITY_REFERENCE_NODE:\\n\\t\\treturn buf.push( '&',node.nodeName,';');\\n\\t//case ENTITY_NODE:\\n\\t//case NOTATION_NODE:\\n\\tdefault:\\n\\t\\tbuf.push('??',node.nodeName);\\n\\t}\\n}\\nfunction importNode(doc,node,deep){\\n\\tvar node2;\\n\\tswitch (node.nodeType) {\\n\\tcase ELEMENT_NODE:\\n\\t\\tnode2 = node.cloneNode(false);\\n\\t\\tnode2.ownerDocument = doc;\\n\\t\\t//var attrs = node2.attributes;\\n\\t\\t//var len = attrs.length;\\n\\t\\t//for(var i=0;i<len;i++){\\n\\t\\t\\t//node2.setAttributeNodeNS(importNode(doc,attrs.item(i),deep));\\n\\t\\t//}\\n\\tcase DOCUMENT_FRAGMENT_NODE:\\n\\t\\tbreak;\\n\\tcase ATTRIBUTE_NODE:\\n\\t\\tdeep = true;\\n\\t\\tbreak;\\n\\t//case ENTITY_REFERENCE_NODE:\\n\\t//case PROCESSING_INSTRUCTION_NODE:\\n\\t////case TEXT_NODE:\\n\\t//case CDATA_SECTION_NODE:\\n\\t//case COMMENT_NODE:\\n\\t//\\tdeep = false;\\n\\t//\\tbreak;\\n\\t//case DOCUMENT_NODE:\\n\\t//case DOCUMENT_TYPE_NODE:\\n\\t//cannot be imported.\\n\\t//case ENTITY_NODE:\\n\\t//case NOTATION_NODE:\\n\\t//can not hit in level3\\n\\t//default:throw e;\\n\\t}\\n\\tif(!node2){\\n\\t\\tnode2 = node.cloneNode(false);//false\\n\\t}\\n\\tnode2.ownerDocument = doc;\\n\\tnode2.parentNode = null;\\n\\tif(deep){\\n\\t\\tvar child = node.firstChild;\\n\\t\\twhile(child){\\n\\t\\t\\tnode2.appendChild(importNode(doc,child,deep));\\n\\t\\t\\tchild = child.nextSibling;\\n\\t\\t}\\n\\t}\\n\\treturn node2;\\n}\\n//\\n//var _relationMap = {firstChild:1,lastChild:1,previousSibling:1,nextSibling:1,\\n//\\t\\t\\t\\t\\tattributes:1,childNodes:1,parentNode:1,documentElement:1,doctype,};\\nfunction cloneNode(doc,node,deep){\\n\\tvar node2 = new node.constructor();\\n\\tfor(var n in node){\\n\\t\\tvar v = node[n];\\n\\t\\tif(typeof v != 'object' ){\\n\\t\\t\\tif(v != node2[n]){\\n\\t\\t\\t\\tnode2[n] = v;\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n\\tif(node.childNodes){\\n\\t\\tnode2.childNodes = new NodeList();\\n\\t}\\n\\tnode2.ownerDocument = doc;\\n\\tswitch (node2.nodeType) {\\n\\tcase ELEMENT_NODE:\\n\\t\\tvar attrs\\t= node.attributes;\\n\\t\\tvar attrs2\\t= node2.attributes = new NamedNodeMap();\\n\\t\\tvar len = attrs.length\\n\\t\\tattrs2._ownerElement = node2;\\n\\t\\tfor(var i=0;i<len;i++){\\n\\t\\t\\tnode2.setAttributeNode(cloneNode(doc,attrs.item(i),true));\\n\\t\\t}\\n\\t\\tbreak;;\\n\\tcase ATTRIBUTE_NODE:\\n\\t\\tdeep = true;\\n\\t}\\n\\tif(deep){\\n\\t\\tvar child = node.firstChild;\\n\\t\\twhile(child){\\n\\t\\t\\tnode2.appendChild(cloneNode(doc,child,deep));\\n\\t\\t\\tchild = child.nextSibling;\\n\\t\\t}\\n\\t}\\n\\treturn node2;\\n}\\n\\nfunction __set__(object,key,value){\\n\\tobject[key] = value\\n}\\n//do dynamic\\ntry{\\n\\tif(Object.defineProperty){\\n\\t\\tObject.defineProperty(LiveNodeList.prototype,'length',{\\n\\t\\t\\tget:function(){\\n\\t\\t\\t\\t_updateLiveList(this);\\n\\t\\t\\t\\treturn this.$$length;\\n\\t\\t\\t}\\n\\t\\t});\\n\\t\\tObject.defineProperty(Node.prototype,'textContent',{\\n\\t\\t\\tget:function(){\\n\\t\\t\\t\\treturn getTextContent(this);\\n\\t\\t\\t},\\n\\t\\t\\tset:function(data){\\n\\t\\t\\t\\tswitch(this.nodeType){\\n\\t\\t\\t\\tcase ELEMENT_NODE:\\n\\t\\t\\t\\tcase DOCUMENT_FRAGMENT_NODE:\\n\\t\\t\\t\\t\\twhile(this.firstChild){\\n\\t\\t\\t\\t\\t\\tthis.removeChild(this.firstChild);\\n\\t\\t\\t\\t\\t}\\n\\t\\t\\t\\t\\tif(data || String(data)){\\n\\t\\t\\t\\t\\t\\tthis.appendChild(this.ownerDocument.createTextNode(data));\\n\\t\\t\\t\\t\\t}\\n\\t\\t\\t\\t\\tbreak;\\n\\t\\t\\t\\tdefault:\\n\\t\\t\\t\\t\\t//TODO:\\n\\t\\t\\t\\t\\tthis.data = data;\\n\\t\\t\\t\\t\\tthis.value = data;\\n\\t\\t\\t\\t\\tthis.nodeValue = data;\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t})\\n\\t\\t\\n\\t\\tfunction getTextContent(node){\\n\\t\\t\\tswitch(node.nodeType){\\n\\t\\t\\tcase ELEMENT_NODE:\\n\\t\\t\\tcase DOCUMENT_FRAGMENT_NODE:\\n\\t\\t\\t\\tvar buf = [];\\n\\t\\t\\t\\tnode = node.firstChild;\\n\\t\\t\\t\\twhile(node){\\n\\t\\t\\t\\t\\tif(node.nodeType!==7 && node.nodeType !==8){\\n\\t\\t\\t\\t\\t\\tbuf.push(getTextContent(node));\\n\\t\\t\\t\\t\\t}\\n\\t\\t\\t\\t\\tnode = node.nextSibling;\\n\\t\\t\\t\\t}\\n\\t\\t\\t\\treturn buf.join('');\\n\\t\\t\\tdefault:\\n\\t\\t\\t\\treturn node.nodeValue;\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\t__set__ = function(object,key,value){\\n\\t\\t\\t//console.log(value)\\n\\t\\t\\tobject['$$'+key] = value\\n\\t\\t}\\n\\t}\\n}catch(e){//ie8\\n}\\n\\n//if(typeof require == 'function'){\\n\\texports.DOMImplementation = DOMImplementation;\\n\\texports.XMLSerializer = XMLSerializer;\\n//}\\n\",\"type\":\"application/javascript\",\"title\":\"$:/plugins/tiddlywiki/xmldom/dom\",\"module-type\":\"library\"},\"$:/plugins/tiddlywiki/xmldom/dom-parser\":{\"text\":\"function DOMParser(options){\\r\\n\\tthis.options = options ||{locator:{}};\\r\\n\\t\\r\\n}\\r\\nDOMParser.prototype.parseFromString = function(source,mimeType){\\r\\n\\tvar options = this.options;\\r\\n\\tvar sax = new XMLReader();\\r\\n\\tvar domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler\\r\\n\\tvar errorHandler = options.errorHandler;\\r\\n\\tvar locator = options.locator;\\r\\n\\tvar defaultNSMap = options.xmlns||{};\\r\\n\\tvar isHTML = /\\\\/x?html?$/.test(mimeType);//mimeType.toLowerCase().indexOf('html') > -1;\\r\\n \\tvar entityMap = isHTML?require('./entities').entityMap:{'lt':'<','gt':'>','amp':'&','quot':'\\\"','apos':\\\"'\\\"};\\r\\n\\tif(locator){\\r\\n\\t\\tdomBuilder.setDocumentLocator(locator)\\r\\n\\t}\\r\\n\\t\\r\\n\\tsax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);\\r\\n\\tsax.domBuilder = options.domBuilder || domBuilder;\\r\\n\\tif(isHTML){\\r\\n\\t\\tdefaultNSMap['']= 'http://www.w3.org/1999/xhtml';\\r\\n\\t}\\r\\n\\tdefaultNSMap.xml = defaultNSMap.xml || 'http://www.w3.org/XML/1998/namespace';\\r\\n\\tif(source){\\r\\n\\t\\tsax.parse(source,defaultNSMap,entityMap);\\r\\n\\t}else{\\r\\n\\t\\tsax.errorHandler.error(\\\"invalid doc source\\\");\\r\\n\\t}\\r\\n\\treturn domBuilder.doc;\\r\\n}\\r\\nfunction buildErrorHandler(errorImpl,domBuilder,locator){\\r\\n\\tif(!errorImpl){\\r\\n\\t\\tif(domBuilder instanceof DOMHandler){\\r\\n\\t\\t\\treturn domBuilder;\\r\\n\\t\\t}\\r\\n\\t\\terrorImpl = domBuilder ;\\r\\n\\t}\\r\\n\\tvar errorHandler = {}\\r\\n\\tvar isCallback = errorImpl instanceof Function;\\r\\n\\tlocator = locator||{}\\r\\n\\tfunction build(key){\\r\\n\\t\\tvar fn = errorImpl[key];\\r\\n\\t\\tif(!fn && isCallback){\\r\\n\\t\\t\\tfn = errorImpl.length == 2?function(msg){errorImpl(key,msg)}:errorImpl;\\r\\n\\t\\t}\\r\\n\\t\\terrorHandler[key] = fn && function(msg){\\r\\n\\t\\t\\tfn('[xmldom '+key+']\\\\t'+msg+_locator(locator));\\r\\n\\t\\t}||function(){};\\r\\n\\t}\\r\\n\\tbuild('warning');\\r\\n\\tbuild('error');\\r\\n\\tbuild('fatalError');\\r\\n\\treturn errorHandler;\\r\\n}\\r\\n\\r\\n//console.log('#\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n####')\\r\\n/**\\r\\n * +ContentHandler+ErrorHandler\\r\\n * +LexicalHandler+EntityResolver2\\r\\n * -DeclHandler-DTDHandler \\r\\n * \\r\\n * DefaultHandler:EntityResolver, DTDHandler, ContentHandler, ErrorHandler\\r\\n * DefaultHandler2:DefaultHandler,LexicalHandler, DeclHandler, EntityResolver2\\r\\n * @link http://www.saxproject.org/apidoc/org/xml/sax/helpers/DefaultHandler.html\\r\\n */\\r\\nfunction DOMHandler() {\\r\\n this.cdata = false;\\r\\n}\\r\\nfunction position(locator,node){\\r\\n\\tnode.lineNumber = locator.lineNumber;\\r\\n\\tnode.columnNumber = locator.columnNumber;\\r\\n}\\r\\n/**\\r\\n * @see org.xml.sax.ContentHandler#startDocument\\r\\n * @link http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html\\r\\n */ \\r\\nDOMHandler.prototype = {\\r\\n\\tstartDocument : function() {\\r\\n \\tthis.doc = new DOMImplementation().createDocument(null, null, null);\\r\\n \\tif (this.locator) {\\r\\n \\tthis.doc.documentURI = this.locator.systemId;\\r\\n \\t}\\r\\n\\t},\\r\\n\\tstartElement:function(namespaceURI, localName, qName, attrs) {\\r\\n\\t\\tvar doc = this.doc;\\r\\n\\t var el = doc.createElementNS(namespaceURI, qName||localName);\\r\\n\\t var len = attrs.length;\\r\\n\\t appendElement(this, el);\\r\\n\\t this.currentElement = el;\\r\\n\\t \\r\\n\\t\\tthis.locator && position(this.locator,el)\\r\\n\\t for (var i = 0 ; i < len; i++) {\\r\\n\\t var namespaceURI = attrs.getURI(i);\\r\\n\\t var value = attrs.getValue(i);\\r\\n\\t var qName = attrs.getQName(i);\\r\\n\\t\\t\\tvar attr = doc.createAttributeNS(namespaceURI, qName);\\r\\n\\t\\t\\tthis.locator &&position(attrs.getLocator(i),attr);\\r\\n\\t\\t\\tattr.value = attr.nodeValue = value;\\r\\n\\t\\t\\tel.setAttributeNode(attr)\\r\\n\\t }\\r\\n\\t},\\r\\n\\tendElement:function(namespaceURI, localName, qName) {\\r\\n\\t\\tvar current = this.currentElement\\r\\n\\t\\tvar tagName = current.tagName;\\r\\n\\t\\tthis.currentElement = current.parentNode;\\r\\n\\t},\\r\\n\\tstartPrefixMapping:function(prefix, uri) {\\r\\n\\t},\\r\\n\\tendPrefixMapping:function(prefix) {\\r\\n\\t},\\r\\n\\tprocessingInstruction:function(target, data) {\\r\\n\\t var ins = this.doc.createProcessingInstruction(target, data);\\r\\n\\t this.locator && position(this.locator,ins)\\r\\n\\t appendElement(this, ins);\\r\\n\\t},\\r\\n\\tignorableWhitespace:function(ch, start, length) {\\r\\n\\t},\\r\\n\\tcharacters:function(chars, start, length) {\\r\\n\\t\\tchars = _toString.apply(this,arguments)\\r\\n\\t\\t//console.log(chars)\\r\\n\\t\\tif(chars){\\r\\n\\t\\t\\tif (this.cdata) {\\r\\n\\t\\t\\t\\tvar charNode = this.doc.createCDATASection(chars);\\r\\n\\t\\t\\t} else {\\r\\n\\t\\t\\t\\tvar charNode = this.doc.createTextNode(chars);\\r\\n\\t\\t\\t}\\r\\n\\t\\t\\tif(this.currentElement){\\r\\n\\t\\t\\t\\tthis.currentElement.appendChild(charNode);\\r\\n\\t\\t\\t}else if(/^\\\\s*$/.test(chars)){\\r\\n\\t\\t\\t\\tthis.doc.appendChild(charNode);\\r\\n\\t\\t\\t\\t//process xml\\r\\n\\t\\t\\t}\\r\\n\\t\\t\\tthis.locator && position(this.locator,charNode)\\r\\n\\t\\t}\\r\\n\\t},\\r\\n\\tskippedEntity:function(name) {\\r\\n\\t},\\r\\n\\tendDocument:function() {\\r\\n\\t\\tthis.doc.normalize();\\r\\n\\t},\\r\\n\\tsetDocumentLocator:function (locator) {\\r\\n\\t if(this.locator = locator){// && !('lineNumber' in locator)){\\r\\n\\t \\tlocator.lineNumber = 0;\\r\\n\\t }\\r\\n\\t},\\r\\n\\t//LexicalHandler\\r\\n\\tcomment:function(chars, start, length) {\\r\\n\\t\\tchars = _toString.apply(this,arguments)\\r\\n\\t var comm = this.doc.createComment(chars);\\r\\n\\t this.locator && position(this.locator,comm)\\r\\n\\t appendElement(this, comm);\\r\\n\\t},\\r\\n\\t\\r\\n\\tstartCDATA:function() {\\r\\n\\t //used in characters() methods\\r\\n\\t this.cdata = true;\\r\\n\\t},\\r\\n\\tendCDATA:function() {\\r\\n\\t this.cdata = false;\\r\\n\\t},\\r\\n\\t\\r\\n\\tstartDTD:function(name, publicId, systemId) {\\r\\n\\t\\tvar impl = this.doc.implementation;\\r\\n\\t if (impl && impl.createDocumentType) {\\r\\n\\t var dt = impl.createDocumentType(name, publicId, systemId);\\r\\n\\t this.locator && position(this.locator,dt)\\r\\n\\t appendElement(this, dt);\\r\\n\\t }\\r\\n\\t},\\r\\n\\t/**\\r\\n\\t * @see org.xml.sax.ErrorHandler\\r\\n\\t * @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html\\r\\n\\t */\\r\\n\\twarning:function(error) {\\r\\n\\t\\tconsole.warn('[xmldom warning]\\\\t'+error,_locator(this.locator));\\r\\n\\t},\\r\\n\\terror:function(error) {\\r\\n\\t\\tconsole.error('[xmldom error]\\\\t'+error,_locator(this.locator));\\r\\n\\t},\\r\\n\\tfatalError:function(error) {\\r\\n\\t\\tconsole.error('[xmldom fatalError]\\\\t'+error,_locator(this.locator));\\r\\n\\t throw error;\\r\\n\\t}\\r\\n}\\r\\nfunction _locator(l){\\r\\n\\tif(l){\\r\\n\\t\\treturn '\\\\n@'+(l.systemId ||'')+'#[line:'+l.lineNumber+',col:'+l.columnNumber+']'\\r\\n\\t}\\r\\n}\\r\\nfunction _toString(chars,start,length){\\r\\n\\tif(typeof chars == 'string'){\\r\\n\\t\\treturn chars.substr(start,length)\\r\\n\\t}else{//java sax connect width xmldom on rhino(what about: \\\"? && !(chars instanceof String)\\\")\\r\\n\\t\\tif(chars.length >= start+length || start){\\r\\n\\t\\t\\treturn new java.lang.String(chars,start,length)+'';\\r\\n\\t\\t}\\r\\n\\t\\treturn chars;\\r\\n\\t}\\r\\n}\\r\\n\\r\\n/*\\r\\n * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/LexicalHandler.html\\r\\n * used method of org.xml.sax.ext.LexicalHandler:\\r\\n * #comment(chars, start, length)\\r\\n * #startCDATA()\\r\\n * #endCDATA()\\r\\n * #startDTD(name, publicId, systemId)\\r\\n *\\r\\n *\\r\\n * IGNORED method of org.xml.sax.ext.LexicalHandler:\\r\\n * #endDTD()\\r\\n * #startEntity(name)\\r\\n * #endEntity(name)\\r\\n *\\r\\n *\\r\\n * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/DeclHandler.html\\r\\n * IGNORED method of org.xml.sax.ext.DeclHandler\\r\\n * \\t#attributeDecl(eName, aName, type, mode, value)\\r\\n * #elementDecl(name, model)\\r\\n * #externalEntityDecl(name, publicId, systemId)\\r\\n * #internalEntityDecl(name, value)\\r\\n * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/EntityResolver2.html\\r\\n * IGNORED method of org.xml.sax.EntityResolver2\\r\\n * #resolveEntity(String name,String publicId,String baseURI,String systemId)\\r\\n * #resolveEntity(publicId, sy