Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Problem - jQuery i XML

[es] :: Javascript i AJAX :: Problem - jQuery i XML

[ Pregleda: 1674 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

deerbeer
Beograd

Član broj: 174418
Poruke: 1189
*.dynamic.sbb.rs.



+395 Profil

icon Problem - jQuery i XML03.11.2011. u 12:21 - pre 151 meseci
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 ?

Viva lollapalooza
 
Odgovor na temu

Nikola Poša
Backend (PHP) developer
Beograd

Član broj: 173839
Poruke: 1616
*.adsl-a-3.sezampro.rs.



+33 Profil

icon Re: Problem - jQuery i XML03.11.2011. u 17:45 - pre 150 meseci
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().
 
Odgovor na temu

deerbeer
Beograd

Član broj: 174418
Poruke: 1189
*.dynamic.sbb.rs.



+395 Profil

icon Re: Problem - jQuery i XML04.11.2011. u 08:41 - pre 150 meseci
Hvala !
Jos jedno pitanje : Da li jquery interno koristi ms-xml parser (i koju veriziju) za ie browsere ?

Viva lollapalooza
 
Odgovor na temu

deerbeer
Beograd

Član broj: 174418
Poruke: 1189
*.dynamic.sbb.rs.



+395 Profil

icon Re: Problem - jQuery i XML11.11.2011. u 10:22 - pre 150 meseci
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
 
Odgovor na temu

[es] :: Javascript i AJAX :: Problem - jQuery i XML

[ Pregleda: 1674 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.