Novo

Forum kao aplikacija na telefonu

Dodajte forum na početni ekran i koristite ga kao aplikaciju, sa menijem na dnu ekrana.

  • 3 odgovora
  • 2.321 pregleda

Najnovija ↓

Problem - jQuery i XML 03.11.2011. u 13:21 · pre 182 meseca #1
Imam neki xml i ucitam ga
Code:
 

  var xmlDoc = jQuery.parseXML(xml);
  var jqXmlDoc =  jQuery(xmlDoc);  
 //setujem vrednosti nekih nodova u xml-u 
. 
. 
. 


Kako da dobijem izmenjeni xml iz jqXmlDoc objekta ?
Potpis
Viva lollapalooza
Re: Problem - jQuery i XML 03.11.2011. u 18:45 · pre 182 meseca #2
Misliš da ponovo dobiješ XML kao string? Onda probaj ovako nešto:
Code:
var xmlStr = xmlDoc.xml ? xmlDoc.xml : (new XMLSerializer()).serializeToString(xmlDoc);

Dakle to radiš direktno nad onim XMLDocument objektom kojeg si dobio preko $.parseXML().
Re: Problem - jQuery i XML 04.11.2011. u 09:41 · pre 182 meseca #3
Hvala !
Jos jedno pitanje : Da li jquery interno koristi ms-xml parser (i koju veriziju) za ie browsere ?
Potpis
Viva lollapalooza
Re: Problem - jQuery i XML 11.11.2011. u 11:22 · pre 182 meseca #4
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;  
    }

}










Potpis
Viva lollapalooza
Prijavite se da biste odgovorili u ovoj temi.PrijavaRegistracija

Premeštanje teme