Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826

    [jquery]parsing xml sincrono

    ciao.
    Ho creato il parsing per un xml come riporto qua sotto:
    codice:
    function ReadXmlFile() {
        var m_Pos = [];//posizione bounding volume  
        var m_scene = [];
        var m_lightmanager = LightsManager;
        
    }
    ReadXmlFile.prototype = {
    
        load: function (render) {
            $.xml("test.xml",{}, function (xml) {
    
                
                $('BVV', xml).each(function readBVV(j) {
    
                    var str = $(this).text().split(" ");
    
                    m_Pos[0] = str[0];
                    m_Pos[1] = str[1];
                    m_Pos[2] = str[2];
                    alert(m_Pos);
                });
    
                $('Textures', xml).each(function readTextures(j) {
                    if ($(this).text().length > 0) {
                        var strTextures = $(this).text().split(";");
                        for (var k = 0; k < strTextures.length; k++) {
                            render.GetTextureManager().initTexture("TexturesModel/" + strTextures[k]);
                            alert("TexturesModel/" + strTextures[k]);
                        }
                    }
                });
    
                $('LightsPositions', xml).each(function readLights(i) {
    
                    $('light', xml).each(function readLight(j) {
                        var str = $(this).text().split(" ");
    
                        var L1 = new Light();
    
                        var col = new Array(4);
                        col[0] = 255;
                        col[1] = 255;
                        col[2] = 255;
                        col[3] = 255;
    
                        L1.SetColor(col);
    
                        var dir = new Array(3);
                        dir[0] = str[0];
                        dir[1] = str[1];
                        dir[2] = str[2];
    
                        L1.SetDirection(dir);
                        render.GetLightManager().add(L1);
    
                    });
    
                });
    
    
                $('Batch', xml).each(function readBatches(i) {
                    var m_Mesh = new Mesh();
                    var vbuffer = new VertexBuffer();
                    var haveUVFront = false;
                    this.vbuffer = new VertexBuffer();
                    this.m_Mesh = new Mesh();
                    var buffer = VertexBuffer();
                    var Material;
    
                    $('MaterialType', $(this)).each(function readMaterialType(i) {
                        Material = $(this).text();
    
                    });
                    var ColorFront = new Array(4);
                    var ColorBack = new Array(4);
    
                    //estraggo il colore front
                    $('ColorFront', $(this)).each(function readColorFront(i) {
    
                        var str = $(this).text().split(" ");
                        ColorFront[0] = parseFloat(str[0]) / 255;
                        ColorFront[1] = parseFloat(str[1]) / 255;
                        ColorFront[2] = parseFloat(str[2]) / 255;
                        ColorFront[3] = parseFloat(str[3]) / 255;
    
                    });
                    //estraggo il coloreback
                    $('ColorBack', $(this)).each(function readColorBack(i) {
    
                        var str = $(this).text().split(" ");
                        ColorBack[0] = parseFloat(str[0]) / 255;
                        ColorBack[1] = parseFloat(str[1]) / 255;
                        ColorBack[2] = parseFloat(str[2]) / 255;
                        ColorBack[3] = parseFloat(str[3]) / 255;
    
                    });
    
                    $('Positions', $(this)).each(function readPosition(i) {
    
                        var str = $(this).text();
    
                        this.item = new ItemData();
                        this.item.AddBulkValue(str, " ");
    
                        vbuffer.SetItemDataAndCreateBuffer(this.item, "position", 3);
    
    
                    });
    
                    $('Normals', $(this)).each(function readNormals(i) {
    
                        var str = $(this).text();
    
                        this.item = new ItemData();
                        this.item.AddBulkValue(str, " ");
                        vbuffer.SetItemDataAndCreateBuffer(this.item, "normal", 3);
    
    
                    });
    
                    $('UVFront', $(this)).each(function readUVFront(i) {
    
                        var str = $(this).text();
                        haveUVFront = true;
                        this.item = new ItemData();
                        this.item.AddBulkValue(str, " ");
    
                        vbuffer.SetItemDataAndCreateBuffer(this.item, "texcoord0", 2);
    
    
                    });
    
                    $('UVBack', $(this)).each(function readUVBack(i) {
    
                        var str = $(this).text();
    
                        haveUVFront = true;
                        this.item = new ItemData();
                        this.item.AddBulkValue(str, " ");
                        vbuffer.SetItemDataAndCreateBuffer(this.item, "texcoord1", 2);
    
    
                    });
    
    
    
                    var material;
                    material = new TextureEffectDouble(ColorBack, ColorFront, "", "", "Script4LightColorV", "Script4LightColorF", m_gl);
                    alert("__________si");
                    alert("vertex buffer1");
                    m_Mesh.AttachMaterial(material);
                    alert("vertex buffer2");
    
                    m_Mesh.SetVertexBuffer(vbuffer);
                    alert("vertex buffer3");
    
                    m_scene.push(m_Mesh);
    
                });
            });
    
    
        },
    il problema è che questo parsing viene effettuato in maniera asincrona, mentre vorrei che fosse eseguito in maniera sincrona.
    Io non ci sono riuscito , ho provato a mettere nelle opzioni(almeno penso siano tali ,correggetemi se sbaglio)
    $.xml("test.xml",{async:false}, function (xml)
    ma non cambia niente.

    Ho visto che l'async : false funziona con ajax , è possibile effettuare il parsing con $ajax se in xml l'async non è supportato?
    come?


    ps.
    ho utilizzato jquery perchè volevo essere certo che che funzionasse sotto tutti i browser.


    grazie.
    grazie.

  2. #2
    Utente di HTML.it
    Registrato dal
    Dec 2010
    Messaggi
    3,660
    ma stai utilizzando un plugin di jquery?

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826
    si , uso jquery ,ma non un plugin , penso sia nel jquery core(se non sbaglio),mi chiedo come fare un parsing di un xml in modo sincrono.
    altra domanda che potrebbe aiutarmi :
    è possibile fare un parsing xml con loggetto ajax sempre con jquery?

    grazie.

  4. #4
    Utente di HTML.it
    Registrato dal
    Dec 2010
    Messaggi
    3,660
    Originariamente inviato da giuseppe500
    si , uso jquery ,ma non un plugin , penso sia nel jquery core(se non sbaglio)
    questo comando $.xml per quanto ne so io non è un comando nativo di jquery, ho spulciato la documentazione ma non ho trovato nessun riferimento. Preso dalla curiosità ho creato un script che utilizza quel comando e ovviamente mi trovo questo errore: $.xml is not a function

    Ora o mi sono completamente rincoglionito(probabile visto che in ufficio dove sto ci sono circa 40 gradi), o quel metodo fa parte di qualche altra libreria esterna.

    è possibile fare un parsing xml con loggetto ajax sempre con jquery?
    Certo è possibile ed è anche abbastanza semplice, in rete trovi moltissimi esempi.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.