8 var parseXML = function(xml) {
12 var Document = function(nativeNode) {
13 var $document = $(nativeNode);
16 Object.defineProperty(this, 'root', {get: function() { return new ElementNode($document[0])}});
20 var ElementNode = function(nativeNode) {
21 this.nativeNode = nativeNode;
22 this._$ = $(nativeNode);
25 $.extend(ElementNode.prototype, {
26 nodeType: Node.ELEMENT_NODE,
28 getTagName: function() {
29 return this.nativeNode.tagName.toLowerCase();
32 append: function(documentNode) {
33 this._$.append(documentNode.nativeNode);
36 contents: function() {
38 this._$.contents().each(function() {
39 if(this.nodeType === Node.ELEMENT_NODE)
40 toret.push(new ElementNode(this));
41 else if(this.nodeType === Node.TEXT_NODE)
42 toret.push(new TextNode(this));
48 sameNode: function(otherNode) {
49 return this.nativeNode === otherNode.nativeNode;
54 var TextNode = function(nativeNode) {
55 this.nativeNode = nativeNode;
56 this._$ = $(nativeNode);
59 $.extend(TextNode.prototype, {
60 nodeType: Node.TEXT_NODE
65 documentFromXML: function(xml) {
66 return new Document(parseXML(xml));
69 elementNodeFromXML: function(xml) {
70 return new ElementNode(parseXML(xml));