0
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ page import= "org.jdom.*, java.util.*, 
org.jdom.input.SAXBuilder,org.jdom.output.XMLOutputter,java.io.*" %>


<%
  SAXBuilder saxBuilder = new SAXBuilder();
  Document doc = saxBuilder.build("http://localhost:8080/cPEP_UI/config.xml");
%>

<html>
  <head><title>Configuration Manager</title></head>
  <body>
    <h1><font color='green'>Configuration Manager</font></h1>
    <%! private String type;
    Element childNode;
    Element create;
    Element parent;
    %>

      <%
      List list = doc.getRootElement().getChildren();
      Iterator iter = list.iterator();

      while (iter.hasNext()){
        Element element = (Element) iter.next();
        List NameDOBCity  = element.getChildren();

        Iterator listIter = NameDOBCity.iterator();
      %>

      <%
        while ( listIter.hasNext() ){
           childNode = (Element) listIter.next();
         String param = request.getParameter(childNode.getName()+childNode.getAttributeValue("id"));

          Enumeration e = request.getParameterNames();
          while(e.hasMoreElements()){
              String s = (String)e.nextElement();
              if(s.equalsIgnoreCase(childNode.getName()))
                  childNode.setText(param);
          }

      %>       




      <%

        }


      }

      XMLOutputter xmlOutputter = new XMLOutputter();
      xmlOutputter.output(doc, new FileWriter("E:/workbench j2ee/cPEP_UI/WebContent/config.xml"));
      %>



  </body>
</html>

** whats wrong with the code?! Its not showing any error, but not changing the element text either. Actually I am making an gui, and need to edit config.xml using textbox in jsp.

1
  • I am trying to edit existing xml file using jdom and then saving it. I am allowing users to edit it using html components like textbox etc. Please help me with this thanks. Commented Mar 13, 2011 at 13:14

1 Answer 1

2

Closing the Filewriter using FileWriter.close() could help...

FileWriter fileWriter = new FileWriter("E:/workbench j2ee/cPEP_UI/WebContent/config.xml");
xmlOutputter.output(doc, fileWriter);
fileWriter.close();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.