Evo klase za manipulaciju sa xml-om ako nekom zatreba :
jquery1.7 rc2 ;
XmlNode:
Code:
function jqXmlNode(domNode) {
this.jqXmlNode = domNode;
this.childNodes = new Array();
for (var i = 0; i < domNode.childNodes.length; i++) {
var node = domNode.childNodes[i];
this.childNodes.push(new jqXmlNode(node));
}
this.attribute = function (name) {
return this.jqXmlNode.getAttribute(name)
}
this.setText = function (value) {
this.jqXmlNode.textContent = value;
}
this.getText = function () {
return this.jqXmlNode.textContent;
}
this.name = function () {
return this.jqXmlNode.nodeName;
}
}
XmlDocument :
Code:
function jqXmlDocument() {
this.jqXmlDoc = null;
this.loadXML = function (xmldata) {
this.jqXmlDoc = jQuery.parseXML(xmldata);
if (this.jqXmlDoc == null)
return false;
return true;
}
this.documentElement = function () {
var ret = null ;
jQuery(this.jqXmlDoc).each(function (i) {
ret = jQuery(this)[0].childNodes[0];
});
return new jqXmlNode(ret);
}
// query nodes
this.selectNode = function (name) {
var retNode = null;
jQuery(this.jqXmlDoc).find(name).each(function (i) {
retNode = new jqXmlNode(this);
});
return retNode ;
}
this.Xml = function (name) {
var xmlString = this.jqXmlDoc.xml ? this.jqXmlDoc.xml : (new XMLSerializer()).serializeToString(this.jqXmlDoc);
return xmlString;
}
}
Viva lollapalooza