1

I was tryng to parse this xml: http://henriquebarone.animatubo.com/spider/jquery/teste.xml

Writing this code:

    $(document).ready(function(){
    $.ajax({
        type: "GET",
        url: "teste.sif",
        dataType: "xml",
        success: Parser 
    });
});

function Parser(sif) {  
    $(sif).find('canvas').each(function(){

        canvas_name = $(this).find('name').text();
        $('<title>'+canvas_name+'</title>').appendTo('head');

        canvas_width = $(this).attr('width');
        canvas_height = $(this).attr('height');
        $('<div id="canvas" style="width:'+canvas_width+'px; height:'+canvas_height+'px; border: solid 1px black; margin: 20px auto"></div>').appendTo('body'); 

        $(this).find('layer').each(function(){
            layer_type = $(this).attr('type');
            if ( layer_type == 'import' ) {
                $(this).find('param').each(function(){
                    param_name = $(this).attr('name');
                    if ( param_name == 'filename' ) {
                        file_name = $(this).find('string').text();
                        $('<div class="import" style="width:50px; height:50px; backgound-img: url('+file_name+')"').appendTo('#canvas');
                    }

                });
            }
        });

    }); 
}

For each <layer> tag with the attribute type="import", I want to get its child <param> with the attribute name="filename", from which I want the text of the <string> tag.

1
  • I've rephrased your question to make it easier to follow, but it's possible I've interpreted it wrong, could you check? Commented Oct 1, 2011 at 17:31

1 Answer 1

1
$(sif).find('layer[type="import"] param[name="filename"] string')

should find what you want. I made a jsFiddle with an example.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.