js如何保存xml

发布时间:2021-07-27 11:09:02 作者:小新
来源:亿速云 阅读:149

这篇文章主要介绍了js如何保存xml,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

.aspx页利用XMLHTTPrequest发送修改过的xml,在接受也接收保存。

主要语句

xmlHttp.open("POST", "receive.aspx?type=xmlsave", true);

xmlHttp.send(xmlDoc);

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function parseXML() {
try //Internet Explorer
           {
              xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
           }
catch (e) {              
try //Firefox, Mozilla, Opera, etc.
               {
                   xmlDoc = document.implementation.createDocument("", "", null);
               }
catch (e) {
                   alert(e.message);
return;
               }
           }
           xmlDoc.async = false; //假如xml载入完毕执行以下
           xmlDoc.load("note.xml");


           xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue = "yaomingming";

var xmlHttp;

try {
// Firefox, Opera 8.0+, Safari
               xmlHttp = new XMLHttpRequest();
           }
catch (e) {

// Internet Explorer
               try {
                   xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
               }
catch (e) {

try {
                       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                   }
catch (e) {
                       alert("您的浏览器不支持AJAX!");
return false;
                   }
               }
           }
           xmlHttp.onreadystatechange = function() {    //onreadystatechange 属性存有处理服务器响应的函数
               if (xmlHttp.readyState == 4) {       //readyState 属性存有服务器响应的状态信息
                   document.getElementById("to").innerHTML = xmlHttp.responseText; //通过 responseText 属性来取回由服务器返回的数据
               }
           }
           xmlHttp.open("POST", "receive.aspx?type=xmlsave", true);

// open() 方法需要三个参数。第一个参数定义发送请求所使用的方法(GET 还是 POST)。第二个参数规定服务器端脚本的 URL。第三个参数规定应当对请求进行异步地处理。
           xmlHttp.send(xmlDoc);      //send() 方法可将请求送往服务器    
}

</script>
</head>
<body onload="parseXML()">
<form id="form1" runat="server">
<p>

    <span id="to"></span>
</p>
</form>
</body>
</html>

receive.aspx.cs

System.IO.Stream instream = Page.Request.InputStream;
                 BinaryReader br = new BinaryReader(instream, System.Text.Encoding.UTF8);
byte[] byt = br.ReadBytes((int)instream.Length);
string sXml = System.Text.Encoding.UTF8.GetString(byt);

                 System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
                 xmlDoc.LoadXml(sXml);
                 xmlDoc.Save(Server.MapPath("note.xml"));

                 Response.Write("save");

感谢你能够认真阅读完这篇文章,希望小编分享的“js如何保存xml”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!

推荐阅读:
  1. Qt Dom方式写xml,以及保存到xml文件中
  2. android保存数据到xml以及pull解析模板

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

xml js

上一篇:代理ip地址被封的原因是什么

下一篇:php中树和二叉树的定义及特点

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》