Best way to parse this XML with jQuery

前端 未结 3 889
别跟我提以往
别跟我提以往 2021-01-26 14:30
 
 
 
  
     127956816         


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

    Assuming you've got the xml as a string, then it should just be:

    var xml = ".....";
    val values = $("date_reception", $(xml))
    
    0 讨论(0)
  • 2021-01-26 14:56

    Use a proper XML parser.

    // http://www.w3schools.com/dom/dom_parser.asp
    function parseXML(text) {
        var doc;
    
        if(window.DOMParser) {
            var parser = new DOMParser();
            doc = parser.parseFromString(text, "text/xml");
        }
        else if(window.ActiveXObject) {
            doc = new ActiveXObject("Microsoft.XMLDOM");
            doc.async = "false";
            doc.loadXML(text);
        }
        else {
            throw new Error("Cannot parse XML");
        }
    
        return doc;
    }
    

    Then get all date reception tag values as

    var xml = parseXML(xmlString);
    $(xml).find('date_reception').each(function() {
        console.log(this.text());
    });
    
    0 讨论(0)
  • 2021-01-26 14:58

    Here is an example of just Javascript to parse, very simple example: http://www.captain.at/howto-ajax-xml-javascript.php

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