What or which plugin in jquery shall i use to populate a html table with a xml file content?

后端 未结 3 602
囚心锁ツ
囚心锁ツ 2021-01-27 13:47

I have a requirement to display data from a xml file from server (path to file something like files/client.xml) into a html table or datagrid, which plugin or rathe

相关标签:
3条回答
  • 2021-01-27 14:01

    Basically, you can read the XML DOM just as you read the HTML DOM, using jQuery selectors. So in your XML example, if you want to do something specific with each <file> element - say, add the contents of it's mount attribute to an unordered list, you could do something like this:

    $(xml).('file').children().each(function() {
        var fileElem = this; // save the instance for closure
        $('ul#theList').append($('<li>').text(fileElem.attr('mount'));
    });
    

    You can get the XML contents with AJAX, using jQuery's built-in AJAX API:

    $.ajax({
        type: "GET",
        url: "your.xml",
        dataType: "xml",
        success: function(xml) {
            // Insert the previous code snippet here
        }
    });
    

    I got all of this from this tutorial, so it might be helpful for you too. Note: This was the very first hit on Google for "jquery xml"...

    0 讨论(0)
  • 2021-01-27 14:12

    jquery.dataTables is good as long as you have control over the contents of the xml file. Their formatting requirements are rather strict.

    0 讨论(0)
  • 2021-01-27 14:19

    You probably want to use XSLT - it will let you take the XML response and directly apply an XSL transform, which can then be inserted into the DOM.

    0 讨论(0)
提交回复
热议问题