mirror of
https://github.com/apache/cordova-android.git
synced 2026-05-30 00:00:04 +08:00
CB-12546: emulator specs.
This commit is contained in:
+24
-22
@@ -2,7 +2,7 @@ function DOMParser(options){
|
||||
this.options = options ||{locator:{}};
|
||||
|
||||
}
|
||||
DOMParser.prototype.parseFromString = function(source,mimeType){
|
||||
DOMParser.prototype.parseFromString = function(source,mimeType){
|
||||
var options = this.options;
|
||||
var sax = new XMLReader();
|
||||
var domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler
|
||||
@@ -25,9 +25,9 @@ DOMParser.prototype.parseFromString = function(source,mimeType){
|
||||
if(source){
|
||||
sax.parse(source,defaultNSMap,entityMap);
|
||||
}else{
|
||||
sax.errorHandler.error("invalid document source");
|
||||
sax.errorHandler.error("invalid doc source");
|
||||
}
|
||||
return domBuilder.document;
|
||||
return domBuilder.doc;
|
||||
}
|
||||
function buildErrorHandler(errorImpl,domBuilder,locator){
|
||||
if(!errorImpl){
|
||||
@@ -77,13 +77,13 @@ function position(locator,node){
|
||||
*/
|
||||
DOMHandler.prototype = {
|
||||
startDocument : function() {
|
||||
this.document = new DOMImplementation().createDocument(null, null, null);
|
||||
this.doc = new DOMImplementation().createDocument(null, null, null);
|
||||
if (this.locator) {
|
||||
this.document.documentURI = this.locator.systemId;
|
||||
this.doc.documentURI = this.locator.systemId;
|
||||
}
|
||||
},
|
||||
startElement:function(namespaceURI, localName, qName, attrs) {
|
||||
var doc = this.document;
|
||||
var doc = this.doc;
|
||||
var el = doc.createElementNS(namespaceURI, qName||localName);
|
||||
var len = attrs.length;
|
||||
appendElement(this, el);
|
||||
@@ -95,24 +95,22 @@ DOMHandler.prototype = {
|
||||
var value = attrs.getValue(i);
|
||||
var qName = attrs.getQName(i);
|
||||
var attr = doc.createAttributeNS(namespaceURI, qName);
|
||||
if( attr.getOffset){
|
||||
position(attr.getOffset(1),attr)
|
||||
}
|
||||
this.locator &&position(attrs.getLocator(i),attr);
|
||||
attr.value = attr.nodeValue = value;
|
||||
el.setAttributeNode(attr)
|
||||
}
|
||||
},
|
||||
endElement:function(namespaceURI, localName, qName) {
|
||||
var current = this.currentElement
|
||||
var tagName = current.tagName;
|
||||
this.currentElement = current.parentNode;
|
||||
var tagName = current.tagName;
|
||||
this.currentElement = current.parentNode;
|
||||
},
|
||||
startPrefixMapping:function(prefix, uri) {
|
||||
},
|
||||
endPrefixMapping:function(prefix) {
|
||||
},
|
||||
processingInstruction:function(target, data) {
|
||||
var ins = this.document.createProcessingInstruction(target, data);
|
||||
var ins = this.doc.createProcessingInstruction(target, data);
|
||||
this.locator && position(this.locator,ins)
|
||||
appendElement(this, ins);
|
||||
},
|
||||
@@ -121,13 +119,17 @@ DOMHandler.prototype = {
|
||||
characters:function(chars, start, length) {
|
||||
chars = _toString.apply(this,arguments)
|
||||
//console.log(chars)
|
||||
if(this.currentElement && chars){
|
||||
if(chars){
|
||||
if (this.cdata) {
|
||||
var charNode = this.document.createCDATASection(chars);
|
||||
this.currentElement.appendChild(charNode);
|
||||
var charNode = this.doc.createCDATASection(chars);
|
||||
} else {
|
||||
var charNode = this.document.createTextNode(chars);
|
||||
var charNode = this.doc.createTextNode(chars);
|
||||
}
|
||||
if(this.currentElement){
|
||||
this.currentElement.appendChild(charNode);
|
||||
}else if(/^\s*$/.test(chars)){
|
||||
this.doc.appendChild(charNode);
|
||||
//process xml
|
||||
}
|
||||
this.locator && position(this.locator,charNode)
|
||||
}
|
||||
@@ -135,7 +137,7 @@ DOMHandler.prototype = {
|
||||
skippedEntity:function(name) {
|
||||
},
|
||||
endDocument:function() {
|
||||
this.document.normalize();
|
||||
this.doc.normalize();
|
||||
},
|
||||
setDocumentLocator:function (locator) {
|
||||
if(this.locator = locator){// && !('lineNumber' in locator)){
|
||||
@@ -145,7 +147,7 @@ DOMHandler.prototype = {
|
||||
//LexicalHandler
|
||||
comment:function(chars, start, length) {
|
||||
chars = _toString.apply(this,arguments)
|
||||
var comm = this.document.createComment(chars);
|
||||
var comm = this.doc.createComment(chars);
|
||||
this.locator && position(this.locator,comm)
|
||||
appendElement(this, comm);
|
||||
},
|
||||
@@ -159,7 +161,7 @@ DOMHandler.prototype = {
|
||||
},
|
||||
|
||||
startDTD:function(name, publicId, systemId) {
|
||||
var impl = this.document.implementation;
|
||||
var impl = this.doc.implementation;
|
||||
if (impl && impl.createDocumentType) {
|
||||
var dt = impl.createDocumentType(name, publicId, systemId);
|
||||
this.locator && position(this.locator,dt)
|
||||
@@ -235,15 +237,15 @@ function _toString(chars,start,length){
|
||||
/* Private static helpers treated below as private instance methods, so don't need to add these to the public API; we might use a Relator to also get rid of non-standard public properties */
|
||||
function appendElement (hander,node) {
|
||||
if (!hander.currentElement) {
|
||||
hander.document.appendChild(node);
|
||||
hander.doc.appendChild(node);
|
||||
} else {
|
||||
hander.currentElement.appendChild(node);
|
||||
}
|
||||
}//appendChild and setAttributeNS are preformance key
|
||||
|
||||
if(typeof require == 'function'){
|
||||
//if(typeof require == 'function'){
|
||||
var XMLReader = require('./sax').XMLReader;
|
||||
var DOMImplementation = exports.DOMImplementation = require('./dom').DOMImplementation;
|
||||
exports.XMLSerializer = require('./dom').XMLSerializer ;
|
||||
exports.DOMParser = DOMParser;
|
||||
}
|
||||
//}
|
||||
|
||||
+130
-33
@@ -110,9 +110,9 @@ NodeList.prototype = {
|
||||
item: function(index) {
|
||||
return this[index] || null;
|
||||
},
|
||||
toString:function(){
|
||||
toString:function(isHTML,nodeFilter){
|
||||
for(var buf = [], i = 0;i<this.length;i++){
|
||||
serializeToString(this[i],buf);
|
||||
serializeToString(this[i],buf,isHTML,nodeFilter);
|
||||
}
|
||||
return buf.join('');
|
||||
}
|
||||
@@ -170,6 +170,7 @@ function _addNamedNode(el,list,newAttr,oldAttr){
|
||||
}
|
||||
}
|
||||
function _removeNamedNode(el,list,attr){
|
||||
//console.log('remove attr:'+attr)
|
||||
var i = _findNodeIndex(list,attr);
|
||||
if(i>=0){
|
||||
var lastIndex = list.length-1
|
||||
@@ -185,7 +186,7 @@ function _removeNamedNode(el,list,attr){
|
||||
}
|
||||
}
|
||||
}else{
|
||||
throw DOMException(NOT_FOUND_ERR,new Error())
|
||||
throw DOMException(NOT_FOUND_ERR,new Error(el.tagName+'@'+attr))
|
||||
}
|
||||
}
|
||||
NamedNodeMap.prototype = {
|
||||
@@ -195,9 +196,11 @@ NamedNodeMap.prototype = {
|
||||
// if(key.indexOf(':')>0 || key == 'xmlns'){
|
||||
// return null;
|
||||
// }
|
||||
//console.log()
|
||||
var i = this.length;
|
||||
while(i--){
|
||||
var attr = this[i];
|
||||
//console.log(attr.nodeName,key)
|
||||
if(attr.nodeName == key){
|
||||
return attr;
|
||||
}
|
||||
@@ -379,7 +382,7 @@ Node.prototype = {
|
||||
}
|
||||
}
|
||||
}
|
||||
el = el.nodeType == 2?el.ownerDocument : el.parentNode;
|
||||
el = el.nodeType == ATTRIBUTE_NODE?el.ownerDocument : el.parentNode;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
@@ -394,7 +397,7 @@ Node.prototype = {
|
||||
return map[prefix] ;
|
||||
}
|
||||
}
|
||||
el = el.nodeType == 2?el.ownerDocument : el.parentNode;
|
||||
el = el.nodeType == ATTRIBUTE_NODE?el.ownerDocument : el.parentNode;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
@@ -579,7 +582,7 @@ Document.prototype = {
|
||||
}
|
||||
return newChild;
|
||||
}
|
||||
if(this.documentElement == null && newChild.nodeType == 1){
|
||||
if(this.documentElement == null && newChild.nodeType == ELEMENT_NODE){
|
||||
this.documentElement = newChild;
|
||||
}
|
||||
|
||||
@@ -599,7 +602,7 @@ Document.prototype = {
|
||||
getElementById : function(id){
|
||||
var rtv = null;
|
||||
_visitNode(this.documentElement,function(node){
|
||||
if(node.nodeType == 1){
|
||||
if(node.nodeType == ELEMENT_NODE){
|
||||
if(node.getAttribute('id') == id){
|
||||
rtv = node;
|
||||
return true;
|
||||
@@ -748,6 +751,7 @@ Element.prototype = {
|
||||
return this.attributes.setNamedItemNS(newAttr);
|
||||
},
|
||||
removeAttributeNode : function(oldAttr){
|
||||
//console.log(this == oldAttr.ownerElement)
|
||||
return this.attributes.removeNamedItem(oldAttr.nodeName);
|
||||
},
|
||||
//get real attribute name,and remove it by removeAttributeNode
|
||||
@@ -792,6 +796,7 @@ Element.prototype = {
|
||||
}
|
||||
});
|
||||
return ls;
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -823,10 +828,7 @@ CharacterData.prototype = {
|
||||
|
||||
},
|
||||
appendChild:function(newChild){
|
||||
//if(!(newChild instanceof CharacterData)){
|
||||
throw new Error(ExceptionMessage[3])
|
||||
//}
|
||||
return Node.prototype.appendChild.apply(this,arguments)
|
||||
throw new Error(ExceptionMessage[HIERARCHY_REQUEST_ERR])
|
||||
},
|
||||
deleteData: function(offset, count) {
|
||||
this.replaceData(offset,count,"");
|
||||
@@ -908,39 +910,132 @@ function ProcessingInstruction() {
|
||||
ProcessingInstruction.prototype.nodeType = PROCESSING_INSTRUCTION_NODE;
|
||||
_extends(ProcessingInstruction,Node);
|
||||
function XMLSerializer(){}
|
||||
XMLSerializer.prototype.serializeToString = function(node,attributeSorter){
|
||||
return node.toString(attributeSorter);
|
||||
XMLSerializer.prototype.serializeToString = function(node,isHtml,nodeFilter){
|
||||
return nodeSerializeToString.call(node,isHtml,nodeFilter);
|
||||
}
|
||||
Node.prototype.toString =function(attributeSorter){
|
||||
Node.prototype.toString = nodeSerializeToString;
|
||||
function nodeSerializeToString(isHtml,nodeFilter){
|
||||
var buf = [];
|
||||
serializeToString(this,buf,attributeSorter);
|
||||
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);
|
||||
if(prefix == null){
|
||||
//isHTML = true;
|
||||
var visibleNamespaces=[
|
||||
{namespace:uri,prefix:null}
|
||||
//{namespace:uri,prefix:''}
|
||||
]
|
||||
}
|
||||
}
|
||||
serializeToString(this,buf,isHtml,nodeFilter,visibleNamespaces);
|
||||
//console.log('###',this.nodeType,uri,prefix,buf.join(''))
|
||||
return buf.join('');
|
||||
}
|
||||
function serializeToString(node,buf,attributeSorter,isHTML){
|
||||
function needNamespaceDefine(node,isHTML, visibleNamespaces) {
|
||||
var prefix = node.prefix||'';
|
||||
var uri = node.namespaceURI;
|
||||
if (!prefix && !uri){
|
||||
return false;
|
||||
}
|
||||
if (prefix === "xml" && uri === "http://www.w3.org/XML/1998/namespace"
|
||||
|| uri == 'http://www.w3.org/2000/xmlns/'){
|
||||
return false;
|
||||
}
|
||||
|
||||
var i = visibleNamespaces.length
|
||||
//console.log('@@@@',node.tagName,prefix,uri,visibleNamespaces)
|
||||
while (i--) {
|
||||
var ns = visibleNamespaces[i];
|
||||
// get namespace prefix
|
||||
//console.log(node.nodeType,node.tagName,ns.prefix,prefix)
|
||||
if (ns.prefix == prefix){
|
||||
return ns.namespace != uri;
|
||||
}
|
||||
}
|
||||
//console.log(isHTML,uri,prefix=='')
|
||||
//if(isHTML && prefix ==null && uri == 'http://www.w3.org/1999/xhtml'){
|
||||
// return false;
|
||||
//}
|
||||
//node.flag = '11111'
|
||||
//console.error(3,true,node.flag,node.prefix,node.namespaceURI)
|
||||
return true;
|
||||
}
|
||||
function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
|
||||
if(nodeFilter){
|
||||
node = nodeFilter(node);
|
||||
if(node){
|
||||
if(typeof node == 'string'){
|
||||
buf.push(node);
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
return;
|
||||
}
|
||||
//buf.sort.apply(attrs, attributeSorter);
|
||||
}
|
||||
switch(node.nodeType){
|
||||
case ELEMENT_NODE:
|
||||
if (!visibleNamespaces) visibleNamespaces = [];
|
||||
var startVisibleNamespaces = visibleNamespaces.length;
|
||||
var attrs = node.attributes;
|
||||
var len = attrs.length;
|
||||
var child = node.firstChild;
|
||||
var nodeName = node.tagName;
|
||||
|
||||
isHTML = (htmlns === node.namespaceURI) ||isHTML
|
||||
buf.push('<',nodeName);
|
||||
if(attributeSorter){
|
||||
buf.sort.apply(attrs, attributeSorter);
|
||||
|
||||
|
||||
|
||||
for(var i=0;i<len;i++){
|
||||
// add namespaces for attributes
|
||||
var attr = attrs.item(i);
|
||||
if (attr.prefix == 'xmlns') {
|
||||
visibleNamespaces.push({ prefix: attr.localName, namespace: attr.value });
|
||||
}else if(attr.nodeName == 'xmlns'){
|
||||
visibleNamespaces.push({ prefix: '', namespace: attr.value });
|
||||
}
|
||||
}
|
||||
for(var i=0;i<len;i++){
|
||||
serializeToString(attrs.item(i),buf,attributeSorter,isHTML);
|
||||
var attr = attrs.item(i);
|
||||
if (needNamespaceDefine(attr,isHTML, visibleNamespaces)) {
|
||||
var prefix = attr.prefix||'';
|
||||
var uri = attr.namespaceURI;
|
||||
var ns = prefix ? ' xmlns:' + prefix : " xmlns";
|
||||
buf.push(ns, '="' , uri , '"');
|
||||
visibleNamespaces.push({ prefix: prefix, namespace:uri });
|
||||
}
|
||||
serializeToString(attr,buf,isHTML,nodeFilter,visibleNamespaces);
|
||||
}
|
||||
if(child || isHTML && !/^(?:meta|link|img|br|hr|input|button)$/i.test(nodeName)){
|
||||
// add namespace for current node
|
||||
if (needNamespaceDefine(node,isHTML, visibleNamespaces)) {
|
||||
var prefix = node.prefix||'';
|
||||
var uri = node.namespaceURI;
|
||||
var ns = prefix ? ' xmlns:' + prefix : " xmlns";
|
||||
buf.push(ns, '="' , uri , '"');
|
||||
visibleNamespaces.push({ prefix: prefix, namespace:uri });
|
||||
}
|
||||
|
||||
if(child || isHTML && !/^(?:meta|link|img|br|hr|input)$/i.test(nodeName)){
|
||||
buf.push('>');
|
||||
//if is cdata child node
|
||||
if(isHTML && /^script$/i.test(nodeName)){
|
||||
if(child){
|
||||
buf.push(child.data);
|
||||
}
|
||||
}else{
|
||||
while(child){
|
||||
serializeToString(child,buf,attributeSorter,isHTML);
|
||||
if(child.data){
|
||||
buf.push(child.data);
|
||||
}else{
|
||||
serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
|
||||
}
|
||||
child = child.nextSibling;
|
||||
}
|
||||
}else
|
||||
{
|
||||
while(child){
|
||||
serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
|
||||
child = child.nextSibling;
|
||||
}
|
||||
}
|
||||
@@ -948,12 +1043,14 @@ function serializeToString(node,buf,attributeSorter,isHTML){
|
||||
}else{
|
||||
buf.push('/>');
|
||||
}
|
||||
// remove added visible namespaces
|
||||
//visibleNamespaces.length = startVisibleNamespaces;
|
||||
return;
|
||||
case DOCUMENT_NODE:
|
||||
case DOCUMENT_FRAGMENT_NODE:
|
||||
var child = node.firstChild;
|
||||
while(child){
|
||||
serializeToString(child,buf,attributeSorter,isHTML);
|
||||
serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
|
||||
child = child.nextSibling;
|
||||
}
|
||||
return;
|
||||
@@ -1098,8 +1195,8 @@ try{
|
||||
},
|
||||
set:function(data){
|
||||
switch(this.nodeType){
|
||||
case 1:
|
||||
case 11:
|
||||
case ELEMENT_NODE:
|
||||
case DOCUMENT_FRAGMENT_NODE:
|
||||
while(this.firstChild){
|
||||
this.removeChild(this.firstChild);
|
||||
}
|
||||
@@ -1110,7 +1207,7 @@ try{
|
||||
default:
|
||||
//TODO:
|
||||
this.data = data;
|
||||
this.value = value;
|
||||
this.value = data;
|
||||
this.nodeValue = data;
|
||||
}
|
||||
}
|
||||
@@ -1118,8 +1215,8 @@ try{
|
||||
|
||||
function getTextContent(node){
|
||||
switch(node.nodeType){
|
||||
case 1:
|
||||
case 11:
|
||||
case ELEMENT_NODE:
|
||||
case DOCUMENT_FRAGMENT_NODE:
|
||||
var buf = [];
|
||||
node = node.firstChild;
|
||||
while(node){
|
||||
@@ -1141,7 +1238,7 @@ try{
|
||||
}catch(e){//ie8
|
||||
}
|
||||
|
||||
if(typeof require == 'function'){
|
||||
//if(typeof require == 'function'){
|
||||
exports.DOMImplementation = DOMImplementation;
|
||||
exports.XMLSerializer = XMLSerializer;
|
||||
}
|
||||
//}
|
||||
|
||||
+13
-10
@@ -10,15 +10,18 @@
|
||||
"spec": ">=0.1.0 <0.2.0",
|
||||
"type": "range"
|
||||
},
|
||||
"/Users/steveng/repo/cordova/cordova-android/node_modules/plist"
|
||||
"/Users/maj/src/cordova-android/node_modules/plist"
|
||||
]
|
||||
],
|
||||
"_from": "xmldom@>=0.1.0 <0.2.0",
|
||||
"_id": "xmldom@0.1.22",
|
||||
"_id": "xmldom@0.1.27",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/xmldom",
|
||||
"_nodeVersion": "5.5.0",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "packages-12-west.internal.npmjs.com",
|
||||
"tmp": "tmp/xmldom-0.1.27.tgz_1480305406093_0.9070004557725042"
|
||||
},
|
||||
"_npmUser": {
|
||||
"name": "jindw",
|
||||
"email": "jindw@xidea.org"
|
||||
@@ -37,11 +40,11 @@
|
||||
"_requiredBy": [
|
||||
"/plist"
|
||||
],
|
||||
"_resolved": "http://registry.npmjs.org/xmldom/-/xmldom-0.1.22.tgz",
|
||||
"_shasum": "10de4e5e964981f03c8cc72fadc08d14b6c3aa26",
|
||||
"_resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.1.27.tgz",
|
||||
"_shasum": "d501f97b3bdb403af8ef9ecc20573187aadac0e9",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "xmldom@0.1.x",
|
||||
"_where": "/Users/steveng/repo/cordova/cordova-android/node_modules/plist",
|
||||
"_where": "/Users/maj/src/cordova-android/node_modules/plist",
|
||||
"author": {
|
||||
"name": "jindw",
|
||||
"email": "jindw@xidea.org",
|
||||
@@ -75,13 +78,13 @@
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "10de4e5e964981f03c8cc72fadc08d14b6c3aa26",
|
||||
"tarball": "https://registry.npmjs.org/xmldom/-/xmldom-0.1.22.tgz"
|
||||
"shasum": "d501f97b3bdb403af8ef9ecc20573187aadac0e9",
|
||||
"tarball": "https://registry.npmjs.org/xmldom/-/xmldom-0.1.27.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.1"
|
||||
},
|
||||
"gitHead": "29a83b315aef56c156602286b2d884a3b4c2521f",
|
||||
"gitHead": "b53aa82a36160d85faab394035dcd1784764537f",
|
||||
"homepage": "https://github.com/jindw/xmldom",
|
||||
"keywords": [
|
||||
"w3c",
|
||||
@@ -132,5 +135,5 @@
|
||||
"scripts": {
|
||||
"test": "proof platform win32 && proof test */*/*.t.js || t/test"
|
||||
},
|
||||
"version": "0.1.22"
|
||||
"version": "0.1.27"
|
||||
}
|
||||
|
||||
+132
-85
@@ -2,21 +2,21 @@
|
||||
//[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
|
||||
//[5] Name ::= NameStartChar (NameChar)*
|
||||
var nameStartChar = /[A-Z_a-z\xC0-\xD6\xD8-\xF6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]///\u10000-\uEFFFF
|
||||
var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\u00B7\u0300-\u036F\\u203F-\u2040]");
|
||||
var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
|
||||
var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
|
||||
//var tagNamePattern = /^[a-zA-Z_][\w\-\.]*(?:\:[a-zA-Z_][\w\-\.]*)?$/
|
||||
//var handlers = 'resolveEntity,getExternalSubset,characters,endDocument,endElement,endPrefixMapping,ignorableWhitespace,processingInstruction,setDocumentLocator,skippedEntity,startDocument,startElement,startPrefixMapping,notationDecl,unparsedEntityDecl,error,fatalError,warning,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,comment,endCDATA,endDTD,endEntity,startCDATA,startDTD,startEntity'.split(',')
|
||||
|
||||
//S_TAG, S_ATTR, S_EQ, S_V
|
||||
//S_ATTR_S, S_E, S_S, S_C
|
||||
//S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
|
||||
//S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
|
||||
var S_TAG = 0;//tag name offerring
|
||||
var S_ATTR = 1;//attr name offerring
|
||||
var S_ATTR_S=2;//attr name end and space offer
|
||||
var S_ATTR_SPACE=2;//attr name end and space offer
|
||||
var S_EQ = 3;//=space?
|
||||
var S_V = 4;//attr value(no quot value only)
|
||||
var S_E = 5;//attr value end and no space(quot end)
|
||||
var S_S = 6;//(attr value end || tag end ) && (space offer)
|
||||
var S_C = 7;//closed el<el />
|
||||
var S_ATTR_NOQUOT_VALUE = 4;//attr value(no quot value only)
|
||||
var S_ATTR_END = 5;//attr value end and no space(quot end)
|
||||
var S_TAG_SPACE = 6;//(attr value end || tag end ) && (space offer)
|
||||
var S_TAG_CLOSE = 7;//closed el<el />
|
||||
|
||||
function XMLReader(){
|
||||
|
||||
@@ -33,7 +33,7 @@ XMLReader.prototype = {
|
||||
}
|
||||
}
|
||||
function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
||||
function fixedFromCharCode(code) {
|
||||
function fixedFromCharCode(code) {
|
||||
// String.prototype.fromCharCode does not supports
|
||||
// > 2 bytes unicode chars directly
|
||||
if (code > 0xffff) {
|
||||
@@ -76,7 +76,7 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
||||
}
|
||||
var lineStart = 0;
|
||||
var lineEnd = 0;
|
||||
var linePattern = /.+(?:\r\n?|\n)|.*$/g
|
||||
var linePattern = /.*(?:\r\n?|\n)|.*$/g
|
||||
var locator = domBuilder.locator;
|
||||
|
||||
var parseStack = [{currentNSMap:defaultNSMapCopy}]
|
||||
@@ -87,7 +87,7 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
||||
var tagStart = source.indexOf('<',start);
|
||||
if(tagStart<0){
|
||||
if(!source.substr(start).match(/^\s*$/)){
|
||||
var doc = domBuilder.document;
|
||||
var doc = domBuilder.doc;
|
||||
var text = doc.createTextNode(source.substr(start));
|
||||
doc.appendChild(text);
|
||||
domBuilder.currentElement = text;
|
||||
@@ -102,16 +102,36 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
||||
var end = source.indexOf('>',tagStart+3);
|
||||
var tagName = source.substring(tagStart+2,end);
|
||||
var config = parseStack.pop();
|
||||
var localNSMap = config.localNSMap;
|
||||
if(config.tagName != tagName){
|
||||
errorHandler.fatalError("end tag name: "+tagName+' is not match the current start tagName:'+config.tagName );
|
||||
}
|
||||
domBuilder.endElement(config.uri,config.localName,tagName);
|
||||
if(localNSMap){
|
||||
for(var prefix in localNSMap){
|
||||
domBuilder.endPrefixMapping(prefix) ;
|
||||
}
|
||||
if(end<0){
|
||||
|
||||
tagName = source.substring(tagStart+2).replace(/[\s<].*/,'');
|
||||
//console.error('#@@@@@@'+tagName)
|
||||
errorHandler.error("end tag name: "+tagName+' is not complete:'+config.tagName);
|
||||
end = tagStart+1+tagName.length;
|
||||
}else if(tagName.match(/\s</)){
|
||||
tagName = tagName.replace(/[\s<].*/,'');
|
||||
errorHandler.error("end tag name: "+tagName+' maybe not complete');
|
||||
end = tagStart+1+tagName.length;
|
||||
}
|
||||
//console.error(parseStack.length,parseStack)
|
||||
//console.error(config);
|
||||
var localNSMap = config.localNSMap;
|
||||
var endMatch = config.tagName == tagName;
|
||||
var endIgnoreCaseMach = endMatch || config.tagName&&config.tagName.toLowerCase() == tagName.toLowerCase()
|
||||
if(endIgnoreCaseMach){
|
||||
domBuilder.endElement(config.uri,config.localName,tagName);
|
||||
if(localNSMap){
|
||||
for(var prefix in localNSMap){
|
||||
domBuilder.endPrefixMapping(prefix) ;
|
||||
}
|
||||
}
|
||||
if(!endMatch){
|
||||
errorHandler.fatalError("end tag name: "+tagName+' is not match the current start tagName:'+config.tagName );
|
||||
}
|
||||
}else{
|
||||
parseStack.push(config)
|
||||
}
|
||||
|
||||
end++;
|
||||
break;
|
||||
// end elment
|
||||
@@ -124,33 +144,40 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
||||
end = parseDCC(source,tagStart,domBuilder,errorHandler);
|
||||
break;
|
||||
default:
|
||||
|
||||
locator&&position(tagStart);
|
||||
|
||||
var el = new ElementAttributes();
|
||||
|
||||
var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
|
||||
//elStartEnd
|
||||
var end = parseElementStartPart(source,tagStart,el,entityReplacer,errorHandler);
|
||||
var end = parseElementStartPart(source,tagStart,el,currentNSMap,entityReplacer,errorHandler);
|
||||
var len = el.length;
|
||||
|
||||
if(locator){
|
||||
if(len){
|
||||
//attribute position fixed
|
||||
for(var i = 0;i<len;i++){
|
||||
var a = el[i];
|
||||
position(a.offset);
|
||||
a.offset = copyLocator(locator,{});
|
||||
}
|
||||
}
|
||||
position(end);
|
||||
}
|
||||
|
||||
if(!el.closed && fixSelfClosed(source,end,el.tagName,closeMap)){
|
||||
el.closed = true;
|
||||
if(!entityMap.nbsp){
|
||||
errorHandler.warning('unclosed xml attribute');
|
||||
}
|
||||
}
|
||||
appendElement(el,domBuilder,parseStack);
|
||||
if(locator && len){
|
||||
var locator2 = copyLocator(locator,{});
|
||||
//try{//attribute position fixed
|
||||
for(var i = 0;i<len;i++){
|
||||
var a = el[i];
|
||||
position(a.offset);
|
||||
a.locator = copyLocator(locator,{});
|
||||
}
|
||||
//}catch(e){console.error('@@@@@'+e)}
|
||||
domBuilder.locator = locator2
|
||||
if(appendElement(el,domBuilder,currentNSMap)){
|
||||
parseStack.push(el)
|
||||
}
|
||||
domBuilder.locator = locator;
|
||||
}else{
|
||||
if(appendElement(el,domBuilder,currentNSMap)){
|
||||
parseStack.push(el)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(el.uri === 'http://www.w3.org/1999/xhtml' && !el.closed){
|
||||
@@ -160,8 +187,10 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
||||
}
|
||||
}
|
||||
}catch(e){
|
||||
errorHandler.error('element parse error: '+e);
|
||||
errorHandler.error('element parse error: '+e)
|
||||
//errorHandler.error('element parse error: '+e);
|
||||
end = -1;
|
||||
//throw e;
|
||||
}
|
||||
if(end>start){
|
||||
start = end;
|
||||
@@ -181,7 +210,7 @@ function copyLocator(f,t){
|
||||
* @see #appendElement(source,elStartEnd,el,selfClosed,entityReplacer,domBuilder,parseStack);
|
||||
* @return end of the elementStartPart(end of elementEndPart for selfClosed el)
|
||||
*/
|
||||
function parseElementStartPart(source,start,el,entityReplacer,errorHandler){
|
||||
function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,errorHandler){
|
||||
var attrName;
|
||||
var value;
|
||||
var p = ++start;
|
||||
@@ -193,7 +222,7 @@ function parseElementStartPart(source,start,el,entityReplacer,errorHandler){
|
||||
if(s === S_ATTR){//attrName
|
||||
attrName = source.slice(start,p);
|
||||
s = S_EQ;
|
||||
}else if(s === S_ATTR_S){
|
||||
}else if(s === S_ATTR_SPACE){
|
||||
s = S_EQ;
|
||||
}else{
|
||||
//fatalError: equal must after attrName or space after attrName
|
||||
@@ -202,25 +231,30 @@ function parseElementStartPart(source,start,el,entityReplacer,errorHandler){
|
||||
break;
|
||||
case '\'':
|
||||
case '"':
|
||||
if(s === S_EQ){//equal
|
||||
if(s === S_EQ || s === S_ATTR //|| s == S_ATTR_SPACE
|
||||
){//equal
|
||||
if(s === S_ATTR){
|
||||
errorHandler.warning('attribute value must after "="')
|
||||
attrName = source.slice(start,p)
|
||||
}
|
||||
start = p+1;
|
||||
p = source.indexOf(c,start)
|
||||
if(p>0){
|
||||
value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
|
||||
el.add(attrName,value,start-1);
|
||||
s = S_E;
|
||||
s = S_ATTR_END;
|
||||
}else{
|
||||
//fatalError: no end quot match
|
||||
throw new Error('attribute value no end \''+c+'\' match');
|
||||
}
|
||||
}else if(s == S_V){
|
||||
}else if(s == S_ATTR_NOQUOT_VALUE){
|
||||
value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
|
||||
//console.log(attrName,value,start,p)
|
||||
el.add(attrName,value,start);
|
||||
//console.dir(el)
|
||||
errorHandler.warning('attribute "'+attrName+'" missed start quot('+c+')!!');
|
||||
start = p+1;
|
||||
s = S_E
|
||||
s = S_ATTR_END
|
||||
}else{
|
||||
//fatalError: no equal before
|
||||
throw new Error('attribute value must after "="');
|
||||
@@ -230,14 +264,14 @@ function parseElementStartPart(source,start,el,entityReplacer,errorHandler){
|
||||
switch(s){
|
||||
case S_TAG:
|
||||
el.setTagName(source.slice(start,p));
|
||||
case S_E:
|
||||
case S_S:
|
||||
case S_C:
|
||||
s = S_C;
|
||||
case S_ATTR_END:
|
||||
case S_TAG_SPACE:
|
||||
case S_TAG_CLOSE:
|
||||
s =S_TAG_CLOSE;
|
||||
el.closed = true;
|
||||
case S_V:
|
||||
case S_ATTR_NOQUOT_VALUE:
|
||||
case S_ATTR:
|
||||
case S_ATTR_S:
|
||||
case S_ATTR_SPACE:
|
||||
break;
|
||||
//case S_EQ:
|
||||
default:
|
||||
@@ -247,30 +281,36 @@ function parseElementStartPart(source,start,el,entityReplacer,errorHandler){
|
||||
case ''://end document
|
||||
//throw new Error('unexpected end of input')
|
||||
errorHandler.error('unexpected end of input');
|
||||
if(s == S_TAG){
|
||||
el.setTagName(source.slice(start,p));
|
||||
}
|
||||
return p;
|
||||
case '>':
|
||||
switch(s){
|
||||
case S_TAG:
|
||||
el.setTagName(source.slice(start,p));
|
||||
case S_E:
|
||||
case S_S:
|
||||
case S_C:
|
||||
case S_ATTR_END:
|
||||
case S_TAG_SPACE:
|
||||
case S_TAG_CLOSE:
|
||||
break;//normal
|
||||
case S_V://Compatible state
|
||||
case S_ATTR_NOQUOT_VALUE://Compatible state
|
||||
case S_ATTR:
|
||||
value = source.slice(start,p);
|
||||
if(value.slice(-1) === '/'){
|
||||
el.closed = true;
|
||||
value = value.slice(0,-1)
|
||||
}
|
||||
case S_ATTR_S:
|
||||
if(s === S_ATTR_S){
|
||||
case S_ATTR_SPACE:
|
||||
if(s === S_ATTR_SPACE){
|
||||
value = attrName;
|
||||
}
|
||||
if(s == S_V){
|
||||
if(s == S_ATTR_NOQUOT_VALUE){
|
||||
errorHandler.warning('attribute "'+value+'" missed quot(")!!');
|
||||
el.add(attrName,value.replace(/&#?\w+;/g,entityReplacer),start)
|
||||
}else{
|
||||
errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!')
|
||||
if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !value.match(/^(?:disabled|checked|selected)$/i)){
|
||||
errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!')
|
||||
}
|
||||
el.add(value,value,start)
|
||||
}
|
||||
break;
|
||||
@@ -287,64 +327,68 @@ function parseElementStartPart(source,start,el,entityReplacer,errorHandler){
|
||||
switch(s){
|
||||
case S_TAG:
|
||||
el.setTagName(source.slice(start,p));//tagName
|
||||
s = S_S;
|
||||
s = S_TAG_SPACE;
|
||||
break;
|
||||
case S_ATTR:
|
||||
attrName = source.slice(start,p)
|
||||
s = S_ATTR_S;
|
||||
s = S_ATTR_SPACE;
|
||||
break;
|
||||
case S_V:
|
||||
case S_ATTR_NOQUOT_VALUE:
|
||||
var value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
|
||||
errorHandler.warning('attribute "'+value+'" missed quot(")!!');
|
||||
el.add(attrName,value,start)
|
||||
case S_E:
|
||||
s = S_S;
|
||||
case S_ATTR_END:
|
||||
s = S_TAG_SPACE;
|
||||
break;
|
||||
//case S_S:
|
||||
//case S_TAG_SPACE:
|
||||
//case S_EQ:
|
||||
//case S_ATTR_S:
|
||||
//case S_ATTR_SPACE:
|
||||
// void();break;
|
||||
//case S_C:
|
||||
//case S_TAG_CLOSE:
|
||||
//ignore warning
|
||||
}
|
||||
}else{//not space
|
||||
//S_TAG, S_ATTR, S_EQ, S_V
|
||||
//S_ATTR_S, S_E, S_S, S_C
|
||||
//S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
|
||||
//S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
|
||||
switch(s){
|
||||
//case S_TAG:void();break;
|
||||
//case S_ATTR:void();break;
|
||||
//case S_V:void();break;
|
||||
case S_ATTR_S:
|
||||
errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead!!')
|
||||
//case S_ATTR_NOQUOT_VALUE:void();break;
|
||||
case S_ATTR_SPACE:
|
||||
var tagName = el.tagName;
|
||||
if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !attrName.match(/^(?:disabled|checked|selected)$/i)){
|
||||
errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead2!!')
|
||||
}
|
||||
el.add(attrName,attrName,start);
|
||||
start = p;
|
||||
s = S_ATTR;
|
||||
break;
|
||||
case S_E:
|
||||
case S_ATTR_END:
|
||||
errorHandler.warning('attribute space is required"'+attrName+'"!!')
|
||||
case S_S:
|
||||
case S_TAG_SPACE:
|
||||
s = S_ATTR;
|
||||
start = p;
|
||||
break;
|
||||
case S_EQ:
|
||||
s = S_V;
|
||||
s = S_ATTR_NOQUOT_VALUE;
|
||||
start = p;
|
||||
break;
|
||||
case S_C:
|
||||
case S_TAG_CLOSE:
|
||||
throw new Error("elements closed character '/' and '>' must be connected to");
|
||||
}
|
||||
}
|
||||
}
|
||||
}//end outer switch
|
||||
//console.log('p++',p)
|
||||
p++;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return end of the elementStartPart(end of elementEndPart for selfClosed el)
|
||||
* @return true if has new namespace define
|
||||
*/
|
||||
function appendElement(el,domBuilder,parseStack){
|
||||
function appendElement(el,domBuilder,currentNSMap){
|
||||
var tagName = el.tagName;
|
||||
var localNSMap = null;
|
||||
var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
|
||||
//var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
|
||||
var i = el.length;
|
||||
while(i--){
|
||||
var a = el[i];
|
||||
@@ -383,7 +427,7 @@ function appendElement(el,domBuilder,parseStack){
|
||||
if(prefix === 'xml'){
|
||||
a.uri = 'http://www.w3.org/XML/1998/namespace';
|
||||
}if(prefix !== 'xmlns'){
|
||||
a.uri = currentNSMap[prefix]
|
||||
a.uri = currentNSMap[prefix || '']
|
||||
|
||||
//{console.log('###'+a.qName,domBuilder.locator.systemId+'',currentNSMap,a.uri)}
|
||||
}
|
||||
@@ -412,7 +456,8 @@ function appendElement(el,domBuilder,parseStack){
|
||||
}else{
|
||||
el.currentNSMap = currentNSMap;
|
||||
el.localNSMap = localNSMap;
|
||||
parseStack.push(el);
|
||||
//parseStack.push(el);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBuilder){
|
||||
@@ -442,7 +487,11 @@ function fixSelfClosed(source,elStartEnd,tagName,closeMap){
|
||||
var pos = closeMap[tagName];
|
||||
if(pos == null){
|
||||
//console.log(tagName)
|
||||
pos = closeMap[tagName] = source.lastIndexOf('</'+tagName+'>')
|
||||
pos = source.lastIndexOf('</'+tagName+'>')
|
||||
if(pos<elStartEnd){//忘记闭合
|
||||
pos = source.lastIndexOf('</'+tagName)
|
||||
}
|
||||
closeMap[tagName] =pos
|
||||
}
|
||||
return pos<elStartEnd;
|
||||
//}
|
||||
@@ -533,7 +582,7 @@ ElementAttributes.prototype = {
|
||||
},
|
||||
length:0,
|
||||
getLocalName:function(i){return this[i].localName},
|
||||
getOffset:function(i){return this[i].offset},
|
||||
getLocator:function(i){return this[i].locator},
|
||||
getQName:function(i){return this[i].qName},
|
||||
getURI:function(i){return this[i].uri},
|
||||
getValue:function(i){return this[i].value}
|
||||
@@ -580,7 +629,5 @@ function split(source,start){
|
||||
}
|
||||
}
|
||||
|
||||
if(typeof require == 'function'){
|
||||
exports.XMLReader = XMLReader;
|
||||
}
|
||||
exports.XMLReader = XMLReader;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user