标签:
<script type="text/javascript">
var xml="<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+"<RecordInfo camId=\"1000000$1$0$0\" count=\"12\" />";
$(function(){
//加载xmlDoc
var xmlDoc=loadXML(xml);
//获取xml指定标签
var tag=xmlDoc.getElementsByTagName("RecordInfo")[0];
//获取标签指定属性值
var attr=tag.getAttribute("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>
标签:
原文地址:http://www.cnblogs.com/shaohaixiong/p/5597531.html