随笔 - 31  文章 - 2  trackbacks - 0

var table = null;
var tbname = null;
var fields = null;
var xmlobject = null;
var fid = null;
var fname = null;
var xmlstring = "<data><table><tbname>abc</tbname><field><fid>fdfd<fid><fname>dfddf</fname></field><field><fid>fdfd<fid><fname>dfddf</fname></field></table>";

xmlstring += "<table><tbname>fgh</tbname><field><fid>dfd<fid><fname>fdf</fname></field></table>";

xmlstring    +="</data>";
try{
      if (window.ActiveXObject)
      {
          xmlobject =new ActiveXObject("Microsoft.XMLDOM");
          xmlobject.async="false";
          xmlobject.loadXML(xmlstring);
      }

      // 用于 Mozilla, Firefox, Opera, 等浏览器的代码:
      else
      {
         var parser=new DOMParser();
         xmlobject =parser.parseFromString(xmlstring,"text/xml");
      }
}catch(e){alert("error");}

var tables = xmlobject.getElementsByTagName("table");
for(var i=0;i<tables.length;i++)
{
    table = tables.item(i);
    tbname = table.getElementsByTagName("tbname")[0].firstChild.nodeValue;
    
    fields = table.getElementsByTagName("field");
    for(var    j=0;j<fields.length;j++)
    {
     sfield = fields.item(j);
     fid= sfield.getElementsByTagName("fid")[0].firstChild.nodeValue;
     fname = sfield.getElementsByTagName("fname")[0].firstChild.nodeValue;
      }
}

posted on 2008-03-08 18:56 缘来如此 阅读(2892) 评论(0)  编辑  收藏 所属分类: XML

只有注册用户登录后才能发表评论。


网站导航: