Reading xml file using javascript

后端 未结 1 1615
[愿得一人]
[愿得一人] 2021-01-22 18:37

I am using the below code to read one xml file which is located locally. But its not displaying the object of xmldoc. My code is

function loadXMLDoc(XMLname)
{
          


        
相关标签:
1条回答
  • 2021-01-22 18:50

    Better use Jquery function. Its working fine for me.

    <script src="jquery.js" type="text/javascript"></script>
    <script>
    $(document).ready(function(){
    $.ajax({
        type: "GET",
        url: "read2.xml",
        dataType: "xml",
        success: function(xml) {
            $(xml).find('site').each(function(){
    
                var id = $(this).attr('id');
                var title = $(this).find('title').text();
                var url = $(this).find('url').text();
                $(this).find('desc').each(function()
                {
                    var brief = $(this).find('brief').text();
                    var long = $(this).find('long').text();
                    alert("my "+brief );
                    alert("my "+long );
    
                });
            });
        }
    });
    });
    

    And the XML file format will be

    my title1 url1

    brf 1 long 1

    brf 2 long 2

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