现在的位置: 首页 > 综合 > 正文

用JS创建一个XML文件

2013年12月07日 ⁄ 综合 ⁄ 共 870字 ⁄ 字号 评论关闭

<script >

   function createXML()

     {

       //创建xml

       Var doc=new ActiveXObject(“Microsoft.XMLDOM”);

       //创建一个根节点,并添加到xml

       Var Root=doc.createElement(“Description”);

       doc.appendChild(Root);

       //向根节点添加属性,setAttribute(key , value);

       Root.setAttribute(“operation”,”search”);

       Root.setAttribute(“eco_no”,document.all(“txtECONO”).value);

       Root.setAttribute(“eco_name”,document.all(“drpEcoName”).options[documeng.all(“drpEcoName”).selectedIndex].value);

      //将xml的值赋给一个hidden控件

      document.getElementById("hidXml").value = doc.xml;

}

</script>

在后台读取xml:

//新建一个XmlDocument实例

XmlDocument xmlDoc=new
XmlDocument
();

//将hidden控件的值生成一个xml

xmlDoc.LoadXml(hidXml.Value.Trim());

//在xml里面,根据key找出value

strring operation = xmlDoc.DocumentElement.GetAttrribute[“operation”];  //根据上面的js赋值,operation= "search"

好了,xml的详细操作这里就不说了,有兴趣的同学可以在博客园里面查一下,挺多资料的。

唉~~发现写篇好的博客好难,自己的表达能力好差。。。。。。。。%>_<%

抱歉!评论已关闭.