JavaScript 解析 XML

<script>


function analyzeXML(strXml)
{
    var objXMLDoc = new ActiveXObject("MSXML.DOMDocument"); 
   
    strXml  = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    strXml += "<Test>";
    strXml += "<Test1>";
    strXml += "<Test2>abc</Test2>";
    strXml += "</Test1>";
    strXml += "</Test>";

    objXMLDoc.async = false;
   
    if( objXMLDoc.loadXML(strXml) )
    {
        //
        alert( objXMLDoc.selectNodes("Test/Test1/Test2").length );  
        alert( objXMLDoc.selectNodes("Test/Test1/Test2")(0).text );        
    }
    else
    {
        //
        alert( "Failed to Load Xml!" );
    }
       
}

analyzeXML("");

</script>

你可能感兴趣的:(JavaScript 解析 XML)