diff --git a/dom.js b/dom.js index 6299445..5c5d641 100644 --- a/dom.js +++ b/dom.js @@ -98,14 +98,14 @@ NodeList.prototype = { * The number of nodes in the list. The range of valid child node indices is 0 to length-1 inclusive. * @standard level1 */ - length:0, + length:0, /** * 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. * @standard level1 - * @param index unsigned long + * @param index unsigned long * Index into the collection. * @return Node - * The node at the indexth position in the NodeList, or null if that is not a valid index. + * The node at the indexth position in the NodeList, or null if that is not a valid index. */ item: function(index) { return this[index] || null; @@ -139,10 +139,10 @@ LiveNodeList.prototype.item = function(i){ _extends(LiveNodeList,NodeList); /** - * + * * 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. * NamedNodeMap objects in the DOM are live. - * used for attributes or DocumentType entities + * used for attributes or DocumentType entities */ function NamedNodeMap() { }; @@ -231,10 +231,10 @@ NamedNodeMap.prototype = { var attr = this.getNamedItem(key); _removeNamedNode(this._ownerElement,this,attr); return attr; - - + + },// raises: NOT_FOUND_ERR,NO_MODIFICATION_ALLOWED_ERR - + //for level2 removeNamedItemNS:function(namespaceURI,localName){ var attr = this.getNamedItemNS(namespaceURI,localName); @@ -297,7 +297,7 @@ DOMImplementation.prototype = { node.systemId = systemId; // Introduced in DOM Level 2: //readonly attribute DOMString internalSubset; - + //TODO:.. // readonly attribute NamedNodeMap entities; // readonly attribute NamedNodeMap notations; @@ -327,10 +327,10 @@ Node.prototype = { prefix : null, localName : null, // Modified in DOM Level 2: - insertBefore:function(newChild, refChild){//raises + insertBefore:function(newChild, refChild){//raises return _insertBefore(this,newChild,refChild); }, - replaceChild:function(newChild, oldChild){//raises + replaceChild:function(newChild, oldChild){//raises this.insertBefore(newChild,oldChild); if(oldChild){ this.removeChild(oldChild); @@ -479,7 +479,7 @@ function _onUpdateChild(doc,el,newChild){ /** * attributes; * children; - * + * * writeable properties: * nodeValue,Attr:value,CharacterData:data * prefix @@ -521,8 +521,8 @@ function _insertBefore(parentNode,newChild,nextChild){ newFirst.previousSibling = pre; newLast.nextSibling = nextChild; - - + + if(pre){ pre.nextSibling = newFirst; }else{ @@ -571,8 +571,8 @@ Document.prototype = { doctype : null, documentElement : null, _inc : 1, - - insertBefore : function(newChild, refChild){//raises + + insertBefore : function(newChild, refChild){//raises if(newChild.nodeType == DOCUMENT_FRAGMENT_NODE){ var child = newChild.firstChild; while(child){ @@ -585,7 +585,7 @@ Document.prototype = { if(this.documentElement == null && newChild.nodeType == ELEMENT_NODE){ this.documentElement = newChild; } - + return _insertBefore(this,newChild,refChild),(newChild.ownerDocument = this),newChild; }, removeChild : function(oldChild){ @@ -611,7 +611,7 @@ Document.prototype = { }) return rtv; }, - + //document factory method: createElement : function(tagName){ var node = new Element(); @@ -735,7 +735,7 @@ Element.prototype = { var attr = this.getAttributeNode(name) attr && this.removeAttributeNode(attr); }, - + //four real opeartion method appendChild:function(newChild){ if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){ @@ -759,7 +759,7 @@ Element.prototype = { var old = this.getAttributeNodeNS(namespaceURI, localName); old && this.removeAttributeNode(old); }, - + hasAttributeNS : function(namespaceURI, localName){ return this.getAttributeNodeNS(namespaceURI, localName)!=null; }, @@ -775,7 +775,7 @@ Element.prototype = { getAttributeNodeNS : function(namespaceURI, localName){ return this.attributes.getNamedItemNS(namespaceURI, localName); }, - + getElementsByTagName : function(tagName){ return new LiveNodeList(this,function(base){ var ls = []; @@ -796,7 +796,7 @@ Element.prototype = { } }); return ls; - + }); } }; @@ -825,7 +825,7 @@ CharacterData.prototype = { }, insertData: function(offset,text) { this.replaceData(offset,0,text); - + }, appendChild:function(newChild){ throw new Error(ExceptionMessage[HIERARCHY_REQUEST_ERR]) @@ -919,7 +919,7 @@ function nodeSerializeToString(isHtml,nodeFilter){ var refNode = this.nodeType == 9 && this.documentElement || this; var prefix = refNode.prefix; var uri = refNode.namespaceURI; - + if(uri && prefix == null){ //console.log(prefix) var prefix = refNode.lookupPrefix(uri); @@ -941,12 +941,12 @@ function needNamespaceDefine(node,isHTML, visibleNamespaces) { if (!prefix && !uri){ return false; } - if (prefix === "xml" && uri === "http://www.w3.org/XML/1998/namespace" + if (prefix === "xml" && uri === "http://www.w3.org/XML/1998/namespace" || uri == 'http://www.w3.org/2000/xmlns/'){ return false; } - - var i = visibleNamespaces.length + + var i = visibleNamespaces.length //console.log('@@@@',node.tagName,prefix,uri,visibleNamespaces) while (i--) { var ns = visibleNamespaces[i]; @@ -985,12 +985,12 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){ var len = attrs.length; var child = node.firstChild; var nodeName = node.tagName; - - isHTML = (htmlns === node.namespaceURI) ||isHTML + + isHTML = (htmlns === node.namespaceURI) ||isHTML buf.push('<',nodeName); - - - + + + for(var i=0;i'); //if is cdata child node @@ -1057,7 +1057,7 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){ case ATTRIBUTE_NODE: return buf.push(' ',node.name,'="',node.value.replace(/[<&"]/g,_xmlEncoder),'"'); case TEXT_NODE: - return buf.push(node.data.replace(/[<&]/g,_xmlEncoder)); + return buf.push(node.data.replace(/[<>&]/g,_xmlEncoder)); case CDATA_SECTION_NODE: return buf.push( ''); case COMMENT_NODE: @@ -1212,7 +1212,7 @@ try{ } } }) - + function getTextContent(node){ switch(node.nodeType){ case ELEMENT_NODE: diff --git a/package.json b/package.json index 610c157..ae8cf75 100644 --- a/package.json +++ b/package.json @@ -1,22 +1,22 @@ { "name": "xmldom", - "version": "0.1.27", + "version": "0.1.28", "description": "A W3C Standard XML DOM(Level2 CORE) implementation and parser(DOMParser/XMLSerializer).", - "keywords": ["w3c","dom","xml","parser","javascript","DOMParser","XMLSerializer"], + "keywords": ["w3c", "dom", "xml", "parser", "javascript", "DOMParser", "XMLSerializer"], "author": "jindw (http://www.xidea.org)", "homepage": "https://github.com/jindw/xmldom", - "repository": {"type": "git","url": "git://github.com/jindw/xmldom.git"}, + "repository": { "type": "git", "url": "git://github.com/jindw/xmldom.git" }, "main": "./dom-parser.js", - "scripts" : { "test": "proof platform win32 && proof test */*/*.t.js || t/test" }, - "engines": {"node": ">=0.1"}, + "scripts": { "test": "proof platform win32 && proof test */*/*.t.js || t/test" }, + "engines": { "node": ">=0.1" }, "dependencies": {}, "devDependencies": { "proof": "0.0.28" }, - "maintainers": [{"name": "jindw","email": "jindw@xidea.org","url": "http://www.xidea.org"}], + "maintainers": [{ "name": "jindw", "email": "jindw@xidea.org", "url": "http://www.xidea.org" }], "contributors": [ - {"name" : "Yaron Naveh","email" : "yaronn01@gmail.com","web" : "http://webservices20.blogspot.com/"}, - {"name" : "Harutyun Amirjanyan","email" : "amirjanyan@gmail.com","web" : "https://github.com/nightwing"}, - {"name" : "Alan Gutierrez","email" : "alan@prettyrobots.com","web" : "http://www.prettyrobots.com/"} + { "name": "Yaron Naveh", "email": "yaronn01@gmail.com", "web": "http://webservices20.blogspot.com/" }, + { "name": "Harutyun Amirjanyan", "email": "amirjanyan@gmail.com", "web": "https://github.com/nightwing" }, + { "name": "Alan Gutierrez", "email": "alan@prettyrobots.com", "web": "http://www.prettyrobots.com/" } ], - "bugs": {"email": "jindw@xidea.org","url": "http://github.com/jindw/xmldom/issues"}, + "bugs": { "email": "jindw@xidea.org", "url": "http://github.com/jindw/xmldom/issues" }, "license": "(LGPL-2.0 or MIT)" -} +} \ No newline at end of file diff --git a/test/dom/serializer.js b/test/dom/serializer.js index d9df5b9..407d44e 100644 --- a/test/dom/serializer.js +++ b/test/dom/serializer.js @@ -5,7 +5,7 @@ wows.describe('XML Serializer').addBatch({ 'text node containing "]]>"': function() { var doc = new DOMParser().parseFromString('', 'text/xml'); doc.documentElement.appendChild(doc.createTextNode('hello ]]> there')); - console.assert(doc.documentElement.firstChild.toString() == 'hello ]]> there',doc.documentElement.firstChild.toString()); + console.assert(doc.documentElement.firstChild.toString() == 'hello ]]> there',doc.documentElement.firstChild.toString()); }, '', 'text/html');