用JS创建一个XML文件

来源:互联网 发布:淘宝助理上传字段错误 编辑:程序博客网 时间:2024/05/22 00:52

<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的详细操作这里就不说了,有兴趣的同学可以在博客园里面查一下,挺多资料的。

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