我如何使用 javascript 写入 xml

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11999989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 15:01:12  来源:igfitidea点击:

How can i write to xml using javascript

javascripthtmlxml

提问by Praveen Singh

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

我对写入 XML 文件的问题感到震惊。我知道如何读取 xml 文件。让我解释清楚。我必须从 xml 文件中读取值并将其传递给标签或列表框,然后将该值写入另一个 xml 文件。我做了阅读的第一部分,我对写作感到震惊。我在 stackoverflow 中经历了几个查询。但它对我不起作用。帮帮我这是我用来编写的代码

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

回答by Awais Qarni

From here

这里

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

that will produce

这将产生

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