<script type="text/javascript">
var xml="<?xml version="1.0" encoding="UTF-8"?>"
+"<RecordInfo camId="1000000$1$0$0" count="12" />";
//js解析xml
$(function(){
//加载xmlDoc
var xmlDoc=loadXML(xml);
//获取xml指定标签
var tag=xmlDoc.getElementsByTagName("RecordInfo")[0];
//获取标签指定属性值
var attr=tag.getAttribute("count");
alert(attr);
});
//jquery解析xml
$(function(){
var xmlStr =loadXML(xml);
var attr=$(xmlStr).find("RecordInfo").attr("count");
alert(attr);
});
var loadXML = function(xmlString)
{
var xmlDoc=null;
if(!window.DOMParser && window.ActiveXObject)
{
var xmlDomVersions = ['MSXML.2.DOMDocument.6.0','MSXML.2.DOMDocument.3.0','Microsoft.XMLDOM'];
for(var i=0;i<xmlDomVersions.length;i++)
{
try
{
xmlDoc = new ActiveXObject(xmlDomVersions[i]);
xmlDoc.async = false;
xmlDoc.loadXML(xmlString); //loadXML方法载入xml字符串
break;
}
catch(e)
{
}
}
}
else if(window.DOMParser && document.implementation && document.implementation.createDocument)
{
try
{
domParser = new DOMParser();
xmlDoc = domParser.parseFromString(xmlString, 'text/xml');
}
catch(e)
{
}
}
else
{
return null;
}
return xmlDoc;
}
</script>