使用javascript创建和修改xml文件 [英] create and modify xml file using javascript

查看:813
本文介绍了使用javascript创建和修改xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建新的xml文件并修改任何xml文件意味着使用javascript在xml文件中添加更多节点。?

How do i create new xml file and also modify any xml file means add more nodes in xml file using javascript.?

提前致谢...

推荐答案

我发现Ariel Flesler的XMLWriter构造函数是从头开始创建XML的良好开端,看看这个

I've found Ariel Flesler's XMLWriter constructor function to be a good start for creating XML from scratch, take a look at this

http:/ /flesler.blogspot.com/2008/03/xmlwriter-for-javascript.html

示例

function test(){    
   var v = new  XMLWriter();
   v.writeStartDocument(true);
   v.writeElementString('test','Hello World');
   v.writeAttributeString('foo','bar');
   v.writeEndDocument();
   console.log( v.flush() );
}

结果

<?xml version="1.0" encoding="ISO-8859-1" standalone="true" ?>
<test foo="bar">Hello World</test>

需要注意的一点是,它不会转义字符串。

One caveat to keep in mind is that it doesn't escape strings.

另请参阅
编写xml的库JavaScript

这篇关于使用javascript创建和修改xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆