XMLDOM解析XML字符串

<script language="JavaScript">

var res="<Messages><Message><ID>1</ID><Title>今天心情不错!</Title></Message><Message><ID>2</ID><Title>明天又要上班了!</Title></Message></Messages>";

function callback(res)
{
 if(res != "")
 {
  var xmlDoc = new ActiveXObject("Microsoft.xmldom"); 
  xmlDoc.async = "false";
  xmlDoc.loadXML(res);
  var mtitles=xmlDoc.getElementsByTagName("Title");
  var mids=xmlDoc.getElementsByTagName("ID");
  var arraylength=mtitles.length;
  var contentArray = new Array();
  var linkArray = new Array();
  alert(arraylength);
  for(i=0;i<arraylength;i++)
  {
   contentArray[i] = mtitles(i).text;
   linkArray[i]='MessageInfoEdit.aspx?MessageInfoID='+mids(i).text;
  }
  for(j=0;j<arraylength;j++)
  {
   document.write(contentArray[j].toString() + " || " + linkArray[j].toString() +"<br/>");
  }
 }
}

callback(res);
</script>

posted @ 2007-01-15 21:42  RobotTech  阅读(2408)  评论(1编辑  收藏  举报