开发者

How to change XML attribute on the client side and then save the result on the server side?

My Question is :

I read a xml file from server 开发者_JAVA技巧side and then present them into client side, next I want to edit the data, like : using setAttribute() method to change them. now here comes problem: I dont want to only modified them on the client side, but on the server side also, and them save the xml file. how can I do that, using JSP and Javascript ? Here is some initial ideas, but some part is not working ... such as the line : " <%count%> = length; "

and i think it is really make the page load slowly if i write xml line by line... is there a better to do this ?

thank you :)

<% 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();  %>


You have to understand that JSP is executed on the server and Javascript will be executed on the client. On the server only the JSP is executed and the result is sent to the server. What your client will receive is the following :

<script>
//read xml file to xmlDoc

var length = xmlDoc.getElementsByTagName("item").length;
 = length;
for(int i = 0; i < length; i++)
{
   xmlDoc.getElementsByTagName("item").item[i].setAttribute("score","1");
    = xmlDoc.getElementsByTagName("item").item[i].setAttribute("score");
}
</script>

Notice that all the JSP tag where executed on the server and what the browser receive is the result. No Javascript is executed on the server.

What you probably want to do is to modify your XML on the server and after that return the result in the page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜