How to parse xml attributes with jQuery alone?

后端 未结 3 1797
名媛妹妹
名媛妹妹 2020-12-31 04:57

I\'m already parsing xml successfully but i\'m stuck at getting an attribute of childrens.

XML Example:


    
        <         


        
相关标签:
3条回答
  • 2020-12-31 05:27

    Aah, namespaces are a different kind of animal, it wasn't in your original post. You have to escape the : in your selector.

    var pic = $entry.find('media\\:thumbnail').attr('url');
    

    http://jsfiddle.net/JSrJe/1/

    See also jQuery XML parsing with namespaces

    0 讨论(0)
  • 2020-12-31 05:29

    try this out

    $.ajax({
        type: "GET",
        url: 'data.xml,
        dataType: "xml",
        success: function(xml) {
            $(xml).find('entry').each(function(){
                var $entry = $(this);
                var pic = $entry.find('picture').attr('url');
                alert(pic);
            })
        },
        error: function(xhr, status, error) {
            if (xhr.status != 404) {alert(error);} else {alert("404 xml not found");}
        }
    })
    
    0 讨论(0)
  • 2020-12-31 05:43
      $.get('data.xml', function(d) {
        $(d).find('entry').each(function() {
            var $entry = $(this);
            var pic = $e`enter code here`ntry.find('media\\:thumbnail, thumbnail').attr('url');
        })
    });
    
    0 讨论(0)
提交回复
热议问题