我如何使用javascript写入xml [英] How can i write to xml using javascript

查看:56
本文介绍了我如何使用javascript写入xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写入XML文件时遇到了麻烦.我知道如何读取xml文件.让我清楚地解释一下.我必须从xml文件读取值并将其传递到标签或列表框,然后将值写入另一个xml文件.我完成了阅读的第一部分,并且在写作方面给我留下了深刻的印象.我在stackoverflow中经历了几个查询.但是它对我不起作用.帮帮我这是我用来编写的代码

i am struck in problem of writing to an XML file. I know how to read an xml file. Let me explain it clearly. I have to read the value from an xml file and pass it to a label or listbox and then write the value to another xml file. I did the first part of reading and i am struck in writing. I have gone through several queries in stackoverflow. But its not working for me. Help me out Here is the code which i used for writing

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

推荐答案

来自这里

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>

这篇关于我如何使用javascript写入xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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