Skip to content

Commit

Permalink
step
Browse files Browse the repository at this point in the history
  • Loading branch information
iazrael committed Apr 24, 2012
1 parent 867cbe7 commit d84e325
Show file tree
Hide file tree
Showing 2 changed files with 2,563 additions and 22 deletions.
84 changes: 62 additions & 22 deletions xmlparser.js
@@ -1,6 +1,5 @@

;(function(undefined){

;Z.$package(function(z, undefined){

/**
* 节点定义
Expand Down Expand Up @@ -35,10 +34,10 @@
//,TODO appendChild, cloneNode, insertBefore, insertAfter, removeChild, replaceChild,
//normalize, contains
//
}

function Element(){
};

function Element(tagName){
this.tagName = tagName;
}

Element.prototype = {
Expand All @@ -56,18 +55,6 @@

},
//============= 扩展的方法 ========================
/*getElementById: function(id){
},
getElementsByTagName: function(tagName){
},
getElementsByName: function(name){
},
getElementsByClassName: function(className){
},*/
/**
* getAttribute和setAttribute的简写
* @param {String} key
Expand All @@ -93,7 +80,7 @@
}
};

Util.extend(Element, Node);
z.extend(Element, Node);

/**
* 文档定义
Expand All @@ -104,9 +91,9 @@

Document.prototype = {

}
};

Util.extend(Document, Element);
z.extend(Document, Element);

function XMLParser(){

Expand All @@ -120,10 +107,63 @@
*/
parse: function(xmlText){
var doc = new Document();
var char, type, start, end, tmp, tag, currNode, attr, value;
for(var i = 0, l = xmlText.length; i < l; i++){
char = xmlText.charAt(i);
switch(char){
case '<':
type = 'tagStart';
tmp = [];
break;
case '>':
break;
case '\/':
break;
case '=':
if(type === 'tagAttrStart'){
type = 'tagAttrValueStart';
attr = tmp.join('');
tmp = [];
}
break;
case ' ':
if(type === 'tagStart'){
type = 'tagAttrStart';
tag = tmp.join('');
tmp = [];
currNode = new Element(tag);
}else if(type === 'tagAttrValueStart'){
value = tmp.join('');
currNode.attr(attr, value);
tmp = [];
type = ??;
}
break;
case '"':
break;
case '-':
break;
case '!':
break;
case '?':
break;
default:
if(type === 'tagStart'){
tmp.push(char);
}else if(type === 'tagAttrStart'){
tmp.push(char);
}else if(type === 'tagAttrValueStart'){
tmp.push(char);
}
break;
}

}

return doc;
}
}
};

window.XMLParser = XMLParser;

})();
});

0 comments on commit d84e325

Please sign in to comment.