在javascript中保存xml [英] saving xml in javascript

查看:61
本文介绍了在javascript中保存xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我有以下问题。我有一个xml文件,而我将在下面列出
列表,我试图根据

用户输入表单向xml文档添加节点。


XML文档是......


<?xml version =" 1.0"?>


< board>

< message>

< authorAuthor One< / author>

< commentThis是第一个测试评论< / comment>

< / message>

< message>

< authorAuthor Two< / author>

< comment这是第二次测试评论< / comment>

< / message>

< message>

< authorAuthor Three< / author>

< commentThis是第三次测试评论< / comment>

< / message>

< / board>

我必须插入新节点的代码是....


< script type =" text / javascript">

var xmlDoc;

var xmlObj;

va作者;

var评论;

var message;

函数loadXMLDoc(){


xmlDoc = new ActiveXObject(" Microsoft.XMLDOM");

xmlDoc.async =" false";

xmlDoc.load(" Guestbook.xml");

xmlObj = xmlDoc.documentElement;

processInput();

}


函数processInput( ){

var new_message = xmlDoc.createElement(''message'');

var new_author = xmlDoc.createElement(''author'');

var new_comment = xmlDoc.createElement(''comment'');

var new_author_text = new_author.createTextNode(''author test

works'');

var new_comment_text = new_comment.createTextNode(''comme nt test

works'');

new_message.appendChild(new_author);

new_message.appendChild(new_comment);

xmlObj.appendChild(new_message);

xmlDoc.save(" Guestbook.xml");

}


< / script>

目前我执行此操作时对xml没有任何改变

档。我所期望的是手动打开xml doc并查看root的4个子节点b $ b节点而不是3节点,如上面xml列表中所示。关于我做错了什么的想法或想法?


另外值得注意的是上面的代码在JSP文件的head部分。

只使用JSP而不是HTML文件,但实际上没有jsp代码在

文件中,只需要html。


谢谢,

Charles

解决方案

ch ********** @ gmail.com 写道:


I有以下问题。我有一个xml文件,而我将在下面列出
,我试图根据

用户输入表单向xml文档添加节点。


xmlDoc = new ActiveXObject(" Microsoft.XMLDOM");


xmlDoc.save(" Guestbook.xml");



是否允许成功调用save方法取决于您的脚本使用的
主机。具有正常安全设置的IE不会

允许,我甚至不确定降低安全设置是否允许它。

但是允许在Windows脚本宿主脚本中调用保存,

ASP页面,在HTML应用程序(HTA)中,命名最常见的主机。

-


Martin Honnen
http://JavaScript.FAQTs.com/



大家好。我有以下问题。我有一个xml文件,而我将在下面列出
列表,我试图根据

用户输入表单向xml文档添加节点。


XML文档是......


<?xml version =" 1.0"?>


< board>

< message>

< authorAuthor One< / author>

< commentThis是第一个测试评论< / comment>

< / message>

< message>

< authorAuthor Two< / author>

< comment这是第二次测试评论< / comment>

< / message>

< message>

< authorAuthor Three< / author>

< commentThis是第三次测试评论< / comment>

< / message>

< / board>


我必须插入新节点的代码是....


< script类型= QUOT;文本/ javasc ript">

var xmlDoc;

var xmlObj;

var author;

var comment;

var message;

函数loadXMLDoc(){


xmlDoc = new ActiveXObject(" Microsoft.XMLDOM");

xmlDoc.async =" false";

xmlDoc.load(" Guestbook.xml");

xmlObj = xmlDoc.documentElement;

processInput();

}


函数processInput(){

var new_message = xmlDoc.createElement (''message'');

var new_author = xmlDoc.createElement(''author'');

var new_comment = xmlDoc.createElement(''comment'' );

var new_author_text = new_author.createTextNode(''author test

works'');

var new_comment_text = new_comment.createTextNode(' '纪念est

作品'');

new_message.appendChild(new_author);

new_message.appendChild(new_comment);

xmlObj.appendChild(new_message);

xmlDoc.save(" Guestbook.xml");

}


< / script>


目前执行此操作时,对xml

文件不做任何更改。我所期望的是手动打开xml doc并查看root的4个子节点b $ b节点而不是3节点,如上面xml列表中所示。关于我做错了什么的想法或想法?


另外值得注意的是上面的代码在JSP文件的head部分。

只使用JSP而不是HTML文件,但实际上没有jsp代码在

文件中,只需要html。


谢谢,

Charles



Desidero appena dire che e un luogo ben cotto http://www.usate348.org/progetti


BizTalk实用工具 - 无懈可击的BizTalk适配器
http://www.topxml.com/biztalkutilities



大家好。我有以下问题。我有一个xml文件,而我将在下面列出
列表,我试图根据

用户输入表单向xml文档添加节点。


XML文档是......


<?xml version =" 1.0"?>


< board>

< message>

< authorAuthor One< / author>

< commentThis是第一个测试评论< / comment>

< / message>

< message>

< authorAuthor Two< / author>

< comment这是第二次测试评论< / comment>

< / message>

< message>

< authorAuthor Three< / author>

< commentThis是第三次测试评论< / comment>

< / message>

< / board>


我必须插入新节点的代码是....


< script类型= QUOT;文本/ javasc ript">

var xmlDoc;

var xmlObj;

var author;

var comment;

var message;

函数loadXMLDoc(){


xmlDoc = new ActiveXObject(" Microsoft.XMLDOM");

xmlDoc.async =" false";

xmlDoc.load(" Guestbook.xml");

xmlObj = xmlDoc.documentElement;

processInput();

}


函数processInput(){

var new_message = xmlDoc.createElement (''message'');

var new_author = xmlDoc.createElement(''author'');

var new_comment = xmlDoc.createElement(''comment'' );

var new_author_text = new_author.createTextNode(''author test

works'');

var new_comment_text = new_comment.createTextNode(' '纪念est

作品'');

new_message.appendChild(new_author);

new_message.appendChild(new_comment);

xmlObj.appendChild(new_message);

xmlDoc.save(" Guestbook.xml");

}


< / script>


目前执行此操作时,对xml

文件不做任何更改。我所期望的是手动打开xml doc并查看root的4个子节点b $ b节点而不是3节点,如上面xml列表中所示。关于我做错了什么的想法或想法?


另外值得注意的是上面的代码在JSP文件的head部分。

只使用JSP而不是HTML文件,但实际上没有jsp代码在

文件中,只需要html。


谢谢,

Charles



mmm ..漂亮的设计,我必须说.. http://www.bovso.org/amici

BizTalk实用工具 - 无懈可击的BizTalk适配器
http://www.topxml.com/biztalkutilities


Hi all. I have the following problem. I have an xml file, while I will
list below and I am trying to add nodes to the xml document based on
user input to a form.

The XML doc is ...

<?xml version="1.0"?>

<board>
<message>
<authorAuthor One </author>
<commentThis is the first test comment </comment>
</message>
<message>
<authorAuthor Two </author>
<commentThis is the second test comment </comment>
</message>
<message>
<authorAuthor Three </author>
<commentThis is the third test comment </comment>
</message>
</board>
The code I have to insert a new node is ....

<script type="text/javascript">
var xmlDoc;
var xmlObj;
var author;
var comment;
var message;
function loadXMLDoc() {

xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load("Guestbook.xml");
xmlObj=xmlDoc.documentElement;
processInput();
}

function processInput() {
var new_message=xmlDoc.createElement(''message'');
var new_author=xmlDoc.createElement(''author'');
var new_comment=xmlDoc.createElement(''comment'');
var new_author_text=new_author.createTextNode(''author test
works'');
var new_comment_text=new_comment.createTextNode(''comme nt test
works'');
new_message.appendChild(new_author);
new_message.appendChild(new_comment);
xmlObj.appendChild(new_message);
xmlDoc.save("Guestbook.xml");
}

</script>
Currently when I execute this is makes no change whatsoever to the xml
file. What I expected was to open the xml doc manually and see 4 child
nodes of the root instead of 3 as shown above in the xml listing. Any
thoughts or ideas on what I''m doing wrong?

Also of note is the above code is in the head section of a JSP file.
Just using JSP instead of HTML file but no jsp code is actually in the
file, just html.

Thanks,
Charles

解决方案

ch**********@gmail.com wrote:

I have the following problem. I have an xml file, while I will
list below and I am trying to add nodes to the xml document based on
user input to a form.

xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

xmlDoc.save("Guestbook.xml");

Whether calling the save method successfully is allowed depends on the
host your script is used in. IE with normal security settings does not
allow that, I am not even sure lowering security settings will allow it.
It is however allowed to call save in a Windows Script Host script, in
an ASP page, in a HTML application (HTA), to name the most common hosts.
--

Martin Honnen
http://JavaScript.FAQTs.com/


Hi all. I have the following problem. I have an xml file, while I will
list below and I am trying to add nodes to the xml document based on
user input to a form.

The XML doc is ...

<?xml version="1.0"?>

<board>
<message>
<authorAuthor One </author>
<commentThis is the first test comment </comment>
</message>
<message>
<authorAuthor Two </author>
<commentThis is the second test comment </comment>
</message>
<message>
<authorAuthor Three </author>
<commentThis is the third test comment </comment>
</message>
</board>
The code I have to insert a new node is ....

<script type="text/javascript">
var xmlDoc;
var xmlObj;
var author;
var comment;
var message;
function loadXMLDoc() {

xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load("Guestbook.xml");
xmlObj=xmlDoc.documentElement;
processInput();
}

function processInput() {
var new_message=xmlDoc.createElement(''message'');
var new_author=xmlDoc.createElement(''author'');
var new_comment=xmlDoc.createElement(''comment'');
var new_author_text=new_author.createTextNode(''author test
works'');
var new_comment_text=new_comment.createTextNode(''comme nt test
works'');
new_message.appendChild(new_author);
new_message.appendChild(new_comment);
xmlObj.appendChild(new_message);
xmlDoc.save("Guestbook.xml");
}

</script>
Currently when I execute this is makes no change whatsoever to the xml
file. What I expected was to open the xml doc manually and see 4 child
nodes of the root instead of 3 as shown above in the xml listing. Any
thoughts or ideas on what I''m doing wrong?

Also of note is the above code is in the head section of a JSP file.
Just using JSP instead of HTML file but no jsp code is actually in the
file, just html.

Thanks,
Charles

Desidero appena dire che e un luogo ben cotto http://www.usate348.org/progetti

BizTalk Utilities - Frustration free BizTalk Adapters
http://www.topxml.com/biztalkutilities


Hi all. I have the following problem. I have an xml file, while I will
list below and I am trying to add nodes to the xml document based on
user input to a form.

The XML doc is ...

<?xml version="1.0"?>

<board>
<message>
<authorAuthor One </author>
<commentThis is the first test comment </comment>
</message>
<message>
<authorAuthor Two </author>
<commentThis is the second test comment </comment>
</message>
<message>
<authorAuthor Three </author>
<commentThis is the third test comment </comment>
</message>
</board>
The code I have to insert a new node is ....

<script type="text/javascript">
var xmlDoc;
var xmlObj;
var author;
var comment;
var message;
function loadXMLDoc() {

xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load("Guestbook.xml");
xmlObj=xmlDoc.documentElement;
processInput();
}

function processInput() {
var new_message=xmlDoc.createElement(''message'');
var new_author=xmlDoc.createElement(''author'');
var new_comment=xmlDoc.createElement(''comment'');
var new_author_text=new_author.createTextNode(''author test
works'');
var new_comment_text=new_comment.createTextNode(''comme nt test
works'');
new_message.appendChild(new_author);
new_message.appendChild(new_comment);
xmlObj.appendChild(new_message);
xmlDoc.save("Guestbook.xml");
}

</script>
Currently when I execute this is makes no change whatsoever to the xml
file. What I expected was to open the xml doc manually and see 4 child
nodes of the root instead of 3 as shown above in the xml listing. Any
thoughts or ideas on what I''m doing wrong?

Also of note is the above code is in the head section of a JSP file.
Just using JSP instead of HTML file but no jsp code is actually in the
file, just html.

Thanks,
Charles

mmm.. nice design, I must say.. http://www.bovso.org/amici

BizTalk Utilities - Frustration free BizTalk Adapters
http://www.topxml.com/biztalkutilities


这篇关于在javascript中保存xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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