如何从 xmlDoc 打印 xml 字符串
How to print xml string from xmlDoc
我正在做的是从服务器读取xml文档,我必须在本地对该xml文档进行修改并将xml文档响应存储在服务器上,但我无法打印更改的xml响应请帮助我!!!
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}
function stringsxmlparsing()
{
console.log("'n'nThis is books.xml demo'n'n");
xmlDoc=loadXMLDoc("books.xml");
//Changing attribute value
x=xmlDoc.getElementsByTagName('string');
x[0].setAttribute("name","food");
//Accessing attribute value
txt=xmlDoc.getElementsByTagName("string")[0].getAttribute("name");
console.log("getAttribute value :"+txt
//here i have to send response xml to server
//I have tried
//console.log(xmlDoc.toXMLString()) but won't worked
}
您需要等待响应,因为 XHR 请求是异步的。
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
parseResponse(xmlhttp.responseXML);
}
}
源:
http://www.w3schools.com/json/json_http.asphttps://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest
相关文章:
- XML字符串转换为JSON javascript
- 使用 javascript 中的表单元素构建一个 xml 字符串
- 从XML字符串创建DOM元素,如何使用.getElementsByName()
- 如何从 xmlDoc 打印 xml 字符串
- 从解析的 XML 构造 XML 字符串
- 将 XML 字符串转换为 org.w3c.dom.Document
- PhoneGap - 如何使用javascript解析xml字符串
- 如何在javascript中解析xml字符串?(不是客户端,与浏览器相关)
- XML 解析错误:使用浏览器内置解析器解析 XML 字符串时格式不正确
- 如何使用 $.parseXML 在客户端上分析包含属性的 xml 字符串
- PHP 似乎不能很好地处理 XML 字符串
- 如何在 javascript 中处理 xml 字符串
- 在 Javascript/JQuery 中搜索 XML 字符串
- 使用 jQuery 更新 XML 字符串
- 删除XML字符串中的返回值
- 如何使用Prototype解析XML字符串
- 使用javascript解析XML字符串
- POST XML字符串到服务器
- 将xml字符串附加到dom.documentElement
- 如何编辑或替换xml字符串使用php