请问怎样将一个xml格式的字符串转换成Dom对象进行访问?
有一个XML的字符串,如
var xml = "
<?xml version= "1.0 " encoding= "GB2312 "?>
<PACKET type= "RESPONSE " version= "1.0 " >
<HEAD>
<REQUEST_TYPE> 50 </REQUEST_TYPE>
<TYPE_CODE> 1 </TYPE_CODE>
<ERROR_MESSAGE> </ERROR_MESSAGE>
</HEAD>
<BODY>
";
请问如何将他转换成DOM文档对象模型,然后用getElemntsByTagName来访问?
------解决方案--------------------var xml = " <?xml version=\ "1.0\ " encoding=\ "GB2312\ "?> <BODY type=\ "RESPONSE\ " version=\ "1.0\ " > <HEAD> <REQUEST_TYPE> 50 </REQUEST_TYPE> <TYPE_CODE> 1 </TYPE_CODE> <ERROR_MESSAGE> </ERROR_MESSAGE> </HEAD> </BODY> ";
doc= new ActiveXObject( "Microsoft.XMLDOM ");
doc.loadXML(xml);
alert(doc.documentElement.xml);