Skip to content

Commit

Permalink
_visitNode/document/and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jindw committed May 22, 2012
1 parent 3b39ccb commit 27fa028
Show file tree
Hide file tree
Showing 11 changed files with 20,286 additions and 225 deletions.
1 change: 1 addition & 0 deletions dom-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ DOMParser.prototype.parseFromString = function(source){
sax.contentHandler = handler;
sax.lexicalHandler = handler;
sax.errorHandler = handler;

sax.parse(source);
return handler.document;
}
Expand Down
44 changes: 9 additions & 35 deletions dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,17 +399,17 @@ copy(NodeType,Node.prototype);

/**
* @param callback return true for continue,false for break
* @return boolean true:continue,false:break;
* @return boolean true: break visit;
*/
function _visitNode(node,callback){
if(callback(node)){
if(node = node.firstChild){
do{
if(!_visitNode(node,callback)){return}
}while(node=node.nextSibling)
}
if(callback(node)){
return true;
}
}
if(node = node.firstChild){
do{
if(_visitNode(node,callback)){return true}
}while(node=node.nextSibling)
}
}


Expand Down Expand Up @@ -543,9 +543,8 @@ Document.prototype = {
if(node.nodeType == 1){
if(node.getAttribute('id') == id){
rtv = node;
return false;
return true;
}
return true;
}
})
return rtv;
Expand Down Expand Up @@ -1007,28 +1006,3 @@ if(typeof require == 'function'){
exports.DOMImplementation = DOMImplementation;
exports.XMLSerializer = XMLSerializer;
}

/*
DOM level2 attribute:
Object Document: doctype|implementation|documentElement
Object Node:
[readonly]: nodeName|nodeType|parentNode|childNodes|firstChild|lastChild|previousSibling|nextSibling|attributes|ownerDocument|namespaceURI|localName
nodeValue|prefix
Object NodeList: length
Object NamedNodeMap: length
Object CharacterData
[readonly]: length
data
Object Attr
[readonly]: name|specified|ownerElement
value
Object Element: tagName
Object DocumentType: name|entities|notations|publicId|systemId|internalSubset
Object Notation: publicId|systemId
Object Entity: publicId|systemId|notationName
Object EntityReference
Object ProcessingInstruction
[readonly]: target
data
*/

122 changes: 122 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,125 @@ Example:
var nsAttr = doc.documentElement.getAttributeNS('./lite','x')
console.info(nsAttr)
console.info(doc)

API Reference
=====
(DOMParser)[https://developer.mozilla.org/en/DOMParser]
parseFromString(xmlsource,mimeType)
(XMLSerializer)[https://developer.mozilla.org/en/XMLSerializer]
serializeToString(node)
DOM level2 method and attribute:
------
(Node)[http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247]
attribute:
nodeValue|prefix
readonly attribute:
nodeName|nodeType|parentNode|childNodes|firstChild|lastChild|previousSibling|nextSibling|attributes|ownerDocument|namespaceURI|localName
method:
insertBefore(newChild, refChild)
replaceChild(newChild, oldChild)
removeChild(oldChild)
appendChild(newChild)
hasChildNodes()
cloneNode(deep)
normalize()
isSupported(feature, version)
hasAttributes()
(DOMImplementation)[http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-102161490]
method:
hasFeature(feature, version)
createDocumentType(qualifiedName, publicId, systemId)
createDocument(namespaceURI, qualifiedName, doctype)
(Document)[http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#i-Document] : Node
readonly attribute:
doctype|implementation|documentElement
method:
createElement(tagName)
createDocumentFragment()
createTextNode(data)
createComment(data)
createCDATASection(data)
createProcessingInstruction(target, data)
createAttribute(name)
createEntityReference(name)
getElementsByTagName(tagname)
importNode(importedNode, deep)
createElementNS(namespaceURI, qualifiedName)
createAttributeNS(namespaceURI, qualifiedName)
getElementsByTagNameNS(namespaceURI, localName)
getElementById(elementId)
(DocumentFragment)[http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-B63ED1A3] : Node
(Element)[http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-745549614] : Node
readonly attribute:
tagName
method:
getAttribute(name)
setAttribute(name, value)
removeAttribute(name)
getAttributeNode(name)
setAttributeNode(newAttr)
removeAttributeNode(oldAttr)
getElementsByTagName(name)
getAttributeNS(namespaceURI, localName)
setAttributeNS(namespaceURI, qualifiedName, value)
removeAttributeNS(namespaceURI, localName)
getAttributeNodeNS(namespaceURI, localName)
setAttributeNodeNS(newAttr)
getElementsByTagNameNS(namespaceURI, localName)
hasAttribute(name)
hasAttributeNS(namespaceURI, localName)
(Attr)[http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-637646024] : Node
attribute:
value
readonly attribute:
name|specified|ownerElement
(NodeList)[http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-536297177]
readonly attribute:
length
method:
item(index)

[NamedNodeMap](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1780488922)
readonly attribute:
length
method:
getNamedItem(name)
setNamedItem(arg)
removeNamedItem(name)
item(index)
getNamedItemNS(namespaceURI, localName)
setNamedItemNS(arg)
removeNamedItemNS(namespaceURI, localName)
(CharacterData)[http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-FF21A306] : Node
method:
substringData(offset, count)
appendData(arg)
insertData(offset, arg)
deleteData(offset, count)
replaceData(offset, count, arg)
(Text)[http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1312295772] : CharacterData
method:
splitText(offset)
(CDATASection)[http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-667469212]
(Comment)[http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1728279322] : CharacterData

(DocumentType)[http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-412266927]
readonly attribute:
name|entities|notations|publicId|systemId|internalSubset
Notation : Node
readonly attribute:
publicId|systemId
Entity : Node
readonly attribute:
publicId|systemId|notationName
EntityReference : Node
ProcessingInstruction : Node
attribute:
data
readonly attribute:
target
DOM level 3 support:
-----
Element : Node
isDefaultNamespace(namespaceURI){
lookupNamespaceURI(prefix)
Loading

0 comments on commit 27fa028

Please sign in to comment.