};
$.extend(ElementNode.prototype, {
+ nodeType: Node.ELEMENT_NODE,
+
getTagName: function() {
return this.nativeNode.tagName.toLowerCase();
},
this._$.contents().each(function() {
if(this.nodeType === Node.ELEMENT_NODE)
toret.push(new ElementNode(this));
+ else if(this.nodeType === Node.TEXT_NODE)
+ toret.push(new TextNode(this));
});
return toret;
},
});
+var TextNode = function(nativeNode) {
+ this.nativeNode = nativeNode;
+ this._$ = $(nativeNode);
+}
+
+$.extend(TextNode.prototype, {
+ nodeType: Node.TEXT_NODE
+})
+
+
return {
documentFromXML: function(xml) {
return new Document(parseXML(xml));
return smartxml.elementNodeFromXML('<' + params.tag + '></' + params.tag + '>');
}
+var elementNodeFromXML = function(xml) {
+ return smartxml.elementNodeFromXML(xml);
+}
+
describe.only('smartxml', function() {
});
});
+ describe('Basic ElementNode properties', function() {
+ it('exposes node contents', function() {
+ var node = elementNodeFromXML('<node>Some<node>text</node>is here</node>'),
+ contents = node.contents();
+
+ expect(contents).to.have.length(3);
+ expect(contents[0].nodeType).to.equal(Node.TEXT_NODE, 'text node 1');
+ expect(contents[1].nodeType).to.equal(Node.ELEMENT_NODE, 'element node 1');
+ expect(contents[2].nodeType).to.equal(Node.TEXT_NODE, 'text node 2');
+ });
+ })
+
describe('Manipulations', function() {
it('appende element node to another element node', function() {