【发布时间】:2011-03-28 12:54:27
【问题描述】:
我的问题是:
我从服务器端读取了一个 xml 文件,然后将它们呈现给客户端,接下来我想编辑数据,例如:使用 setAttribute() 方法来更改它们。现在问题来了: 我不想只在客户端修改它们,但也在服务器端,它们保存 xml 文件。我怎么能做到这一点,使用 JSP 和 Javascript ? 这是一些初步的想法,但有些部分不起作用...... 如行:“ = length;”
而且我认为如果我逐行编写 xml 确实会使页面加载缓慢... 有没有更好的办法?
谢谢你:)
<% String attribute[];
int count; %>
<script>
//hide the part of reading xml file to xmlDoc
var length = xmlDoc.getElementsByTagName("item").length;
<%count%> = length; // this doesnt work ...???
for(int i = 0; i < length; i++)
{
xmlDoc.getElementsByTagName("item").item[i].setAttribute("score","1");
<%attribute[i]%> = xmlDoc.getElementsByTagName("item").item[i].setAttribute("score");
}
</script>
<% String xmlString;
String personNm ={"Bob","Mike","Lily"};
for (int i;i < count;i++)
xmlString = "<person score="+attribute[i]+">personNm[i]</person>";
//here i use a out put buffer to print it line by line...
outputFile = new File("result.xml");
outputFile.createNewFile();
FileWriter outfile = new FileWriter(outputFile);
outfile.write(xmlString);
outfile.close(); %>
【问题讨论】:
-
如果你想让某人感兴趣,你需要在提问时下功夫!
-
@enguerran 做了什么努力?...添加更多标签?还是?
-
注意演示。英语语言和代码格式。
-
正如 BalusC 所说:注意演示。
-
是的,谢谢,你说得对,我又修改了一遍,希望现在更清楚,但我不是来自英语国家...所以我尽力了:)
标签: javascript xml ajax jsp xml-parsing