How do I create an XML file through a JSP?

I want to have a JSP which allows the user to create an account with password and this is stored in an XML file. I would like to b e able to amend this XML file with future users of the JSP but I'm not sure how to do this. I can do it using a database converting that to XML and then save the user input but I don't want to use a DB this time. Can some body give me an example. It the closing XML tag I have trouble with. I could amend the file but the previuos entry would close the XML file and then the newest entry would add on in effect an new XML file to the previous. Hope you can understand what I'm saying?!
I have a file with:
<topic>
<--- this is where I want to store my data!
</topic>
Michael

Use JDOM ... Here's a tutorial where you create a DOM and save it to an xml file ...
http://www.topxml.com/tutorials/main.asp?id=jdom&page=15

Similar Messages

  • How I can create a XML file from java Aplication

    How I can create a XML file from java Aplication
    whith have a the following structure
    <users>
    <user>
    <login>anyName</login>     
    <password>xxxx</password>
    </user>
    </users>
    the password label must be encripted
    accept any suggestion

    Let us assume you have all the data from the jsp form in an java bean object..
    Now you want a xml file. This can be acheived in 2 ways
    1. Write it into a file using java.io classes. Say you have a class with name
    write("<name>"+obj.getName+</name>);
    bingo you have a flat file with the xml
    2. Use data binding to do the trick
    will recommend JiBx and Castor for the 2nd option
    Regards,
    Rajagopal

  • How do I create individual xml files from the parsed data output of a xml file?

    I have written a program (DOM Parser) that parses data from a XMl File. I would like to create an individual file with the corresponding name for each set of data parsed from the xml document. If the parsed output is Single, Double, Triple, I would like to create an individual xml file (Single.xml, Double.xml, Triple.xml)with those corresponding names. How do I create the xml files and give each file the name of my parsed data output? Thanks in advance for your help.
    import java.io.IOException;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
    public class MyDomParser {
      public static void main(String[] args) {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      try {
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document doc = builder.parse("ENtemplate.xml");
      doc.normalize();
      NodeList rootNodes = doc.getElementsByTagName("templates");
      Node rootNode = rootNodes.item(0);
      Element rootElement = (Element) rootNode;
      NodeList templateList = rootElement.getElementsByTagName("template");
      for(int i=0; i < templateList.getLength(); i++) {
      Node theTemplate = templateList.item(i);
      Element templateElement = (Element) theTemplate;
      System.out.println("Template" + ": " +templateElement.getAttribute("name")+ ".xml");
      } catch (ParserConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();

    Ive posted the new code but now I'm getting a FileAlreadyExistException error. How do I handle this exception error correctly in my code?
    import java.io.IOException;
    import java.nio.file.FileAlreadyExistsException;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
    public class MyDomParser {
      public static void main(String[] args) {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      try {
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document doc = builder.parse("ENtemplate.xml");
      doc.normalize();
      NodeList rootNodes = doc.getElementsByTagName("templates");
      Node rootNode = rootNodes.item(0);
      Element rootElement = (Element) rootNode;
      NodeList templateList = rootElement.getElementsByTagName("template");
      for(int i=0; i < templateList.getLength(); i++) {
      Node theTemplate = templateList.item(i);
      Element templateElement = (Element) theTemplate;
      System.out.println(templateElement.getAttribute("name")+ ".xml");
      for(int i=0; i < templateList.getLength(); i++) {
      Node theTemplate = templateList.item(i);
      Element templateElement = (Element) theTemplate;
      String fileName = templateElement.getAttribute("name") + ".xml";
      Files.createFile(Paths.get(fileName));
      System.out.println("File" + ":" + fileName + ".xml created");
      } catch (ParserConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();

  • How to create a xml file from the jsp page?

    I'm a beginner of the develop xml,my question like this,
    there has a jsp page,some parameters in it,I wanna get the parameters and create a xml file,so,what parser method should I use?
    And how to create a new xml file,when the file haven't exist at first?
    pls give some code,thanks.

    a ggod link for u http://www.theserverside.com/resources/article.jsp?l=JSP-XML2

  • How to create an XML File for Gantt?

    Hi Everybody.
    I need a Gantt in Web Dynpro ABAP. I need it for the boss to do a Forecast for Vacation. I Hope this is understanding.
    Did Anyone know how can i create a XML File for the Gantt at runtime?
    Thanks
    MSi

    Hi Marcus,
    the following link is to the JNet/JGantt developer doco
    [JNet/JGantt Developer Documentation|http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/lw/uuid/f010ec31-9658-2910-3c83-c6e62904eceb]
    included in this is the:
    [Schema for XML|http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/com.sap.km.cm.docs/lw/webdynpro/jnet_jgantt%20developer%20documentation/schema/xml-spy/jnet-schema.html]
    You can use this to build XML to represent a gantt like chart.
    I did this to build XML to represent employee avaliablity - although we fronted the gantt through WD Java not ABAP - the java applet called is the same (I believe).
    Don't underestimate the work required to tweek your data into a decent layout. It took me days.
    There may be tools/api to help generate the XML - I don't know of them - I'd look forward to seeing any other replies to this thread from people who have used/built any.  An example of a class that generates JNet XML - CL_SPI_UI_JNET - but this does not seem to be a Gantt display.
    Cheers,
    Chris

  • How to make a bean create an xml file..

    How does one create an xml file from a bean?
    If anyone have the answer, or some sample code I would really apprecciate it!!!
    In advance thanx a lot!!!

    just "wrap" this up in a bean.
    import java.io.*;
    import org.jdom.*;
    import org.jdom.output.*;
    /** Make up and write an XML document, using JDOM
    * @author Ian Darwin, [email protected]
    * @version $Id: DocWriteJDOM.java,v 1.2 2001/11/21 23:08:17 ian Exp $
    public class DocWriteJDOM {
         public static void main(String[] av) throws Exception {
              DocWriteJDOM dw = new DocWriteJDOM();
              Document doc = dw.makeDoc();
              // Create an output formatter, and have it write the doc.
              new XMLOutputter().output(doc, System.out);
         /** Generate the XML document */
         protected Document makeDoc() throws Exception {
                   Document doc = new Document(new Element("Poem"));
                   doc.getRootElement().
                        addContent(new Element("Stanza").
                             addContent(new Element("Line").
                                       setText("Once, upon a midnight dreary")).
                             addContent(new Element("Line").
                                       setText("While I pondered, weak and weary")));
                   return doc;

  • How do your create an xml glossary file?

    Everyone talks about importing the glossary from an xml file , even from one created from Excel. I have browsed until my fingers bleed and watched the tutorials and seached the Captivate files to try and find a glossary root file to work with.
    Please excuse my Newb question but how to I create an xml file, specially using Excel (the easiest way for me to set up a Glossary)?  Is there an example I can work off? How do I paste the import xml tags as offered in the widgit to such a file.
    This glosary file will be imported and used in to approximately 40 modules so obviously I want just one file to work with.
    Again sorry for the newb question.

    Hi Jeremia,
    From one newb to another ;o)
    I ditched the whole thing  as soon as I figured it out because putting the glossary in to the captivate slides was really clunky and not a neat solution. Instead we are using our custom written background database and having a glossary link in the main navigation menu, a luxury many captivate scorm projects would not have.
    However the spreadsheet is a way of writing all the tags needed for the xml code (fill down). Just highlight ALL the cells with all the tags as per the screen shot, copy and then paste in the open dreamweaver page. However, make sure the dreamweaver page is an xml page. You can then use the xml dreamwever page as the import in to captivate.
    Because you are copying from a spreadsheet the paste action in dreamweaver will insert tabs between the data of the cell. You get rid of this by doing a search and replace...search for the tab and replace with nothing, effectively deleting the unwanted tabs.
    It is highly inelegant but it works.
    Hope this helps and does not confuse it further.
    Re: How do your create an xml glossary file?
    created by bittymiah83 in Adobe Captivate - View the full discussion
    This is very helpful - I'm just missing the piece of how I import the excel data into the Dreamweaver code. Am I repeating the same code over and over in Dreamweaver and cutting and pasting from the excel file?
    I'm a newb also so any help would be appreciated!
    Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/6173858#6173858
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/6173858#6173858
    To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/6173858#6173858. In the Actions box on the right, click the Stop Email Notifications link.
    Start a new discussion in Adobe Captivate at Adobe Community
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/thread/416458?tstart=0.

  • Read an xml file through file adapter?

    How do i read an xml file through file adapter?

    Hi,
      This is pretty straight forward.
    Just configure the sender file adapter without any file content conversions.
    Read this for more information:
    http://help.sap.com/saphelp_nw04/helpdata/EN/e3/94007075cae04f930cc4c034e411e1/content.htm
    Regards,
    Ravi

  • How to deploy the web.xml file when trying to use the JSP SDK from SAP?

    I want to use the adduser.jsp which downloaded form SAP SDK samples to add user in BO, but I cannot run it sucessfully. I believe it's caused the web.xml file was not deployed appropriately.
    could you please teach how to deploy the web.xml file for the JSP samples ?
    Could you show me some sample of web.xml for the SDK jsp files? Thank you very much!

    Ensure that you have followed below directory structure while deploying your web application.
       web_application_name
          WEB-INF
             lib
             classes
    web.xml must be placed in WEB-INF. Ensure that you have included all the jar files and other necessary files in your application.
    For more information refer to the below link:
    http://devlibrary.businessobjects.com/BusinessObjectsXIR2SP2/en/devsuite.htm
    Regards,
    Anuj

  • Writing XML file from a jsp page

    how can i write a xml file from my jsp and store the values and after sometime, for example when the user clicks on the submit button, i check the values from xml file and compare those values from the data base.
    it means both writing and reading xml file from a jsp page...
    urgent help needed......thanks

    You need some API like XSL or JDOM to read data from/to XML file
    you can get a best tutorial from
    http://www.javaworld.com/javaworld/jw-05-2000/jw-0518-jdom.html
    and
    http://www.javaworld.com/javaworld/jw-07-2000/jw-0728-jdom2.html
    after reading both articals you will be able to do both the tasks

  • How to create xml file through SDK?

    Hi,
    I need help in creating the xml file using SAP B1 SDK?
    i want to create xml file which is in tally xml format.
    Warm Ragards,
    Mahendra

    Hi Mahendra,
    This is an example to save a form as XML :
    try
                    System.Xml.XmlDocument oXmlDoc = null;
                    string sXmlString = null;
                    oXmlDoc = new System.Xml.XmlDocument();
                    // get the form as an XML string
                    sXmlString = Form.GetAsXML();
                    // load the form's XML string to the
                    // XML document object
                    oXmlDoc.LoadXml(sXmlString);
                    string sPath = null;
                    sPath = System.IO.Directory.GetParent(System.Windows.Forms.Application.StartupPath).ToString();
                    sPath = System.IO.Directory.GetParent(sPath).ToString();
                    // save the XML Document
                    oXmlDoc.Save((sPath + @"\Form" + sType + ".xml"));
                    //oXmlDoc.Save(DIRECTORY_TEMPLATE + "Form" + sType + ".xml");
                catch (Exception ex)
                    SBO_Application.MessageBox("ERROR in 'SaveAsXML()' : " + ex.Message, 1, "Ok", "", "");
    And an example to navigate in the XML file :
    System.Xml.XmlDocument xxml;
                                    System.Xml.XmlNode node;
                                    System.Xml.XmlNodeList nodes;
                                    xxml = new System.Xml.XmlDocument();
                                    xxml.LoadXml(oRecAU.GetAsXML());
                                    nodes = xxml.SelectNodes("BOM/BO/IFC_AU/row");
                                    foreach (System.Xml.XmlNode node in nodes)
                                        oColumn.ValidValues.Add(node.SelectSingleNode("Code").InnerText, node.SelectSingleNode("Name").InnerText);
    I hope it's help you.
    Regards
    Michael

  • How to create new XML file using retreived XML content by using SAX API?

    hi all,
    * How to create new XML file using retreived XML content by using SAX ?
    * I have tried my level best, but output is coming invalid format, my code is follows,
    XMLFileParser.java class :-
    import java.io.StringReader;
    import java.io.StringWriter;
    import javax.xml.transform.OutputKeys;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerConfigurationException;
    import javax.xml.transform.TransformerException;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMResult;
    import javax.xml.transform.sax.SAXSource;
    import javax.xml.transform.sax.SAXTransformerFactory;
    import javax.xml.transform.sax.TransformerHandler;
    import javax.xml.transform.stream.StreamResult;
    import org.w3c.dom.Document;
    import org.xml.sax.Attributes;
    import org.xml.sax.InputSource;
    import org.xml.sax.SAXException;
    import org.xml.sax.helpers.XMLFilterImpl;
    public class PdfParser extends XMLFilterImpl {
        private TransformerHandler handler;
        Document meta_data;
        private StringWriter meta_data_text = new StringWriter();
        public void startDocument() throws SAXException {
        void startValidation() throws SAXException {
            StreamResult streamResult = new StreamResult(meta_data_text);
            SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
            try
                handler = factory.newTransformerHandler();
                Transformer transformer = handler.getTransformer();
                transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                handler.setResult(streamResult);
                handler.startDocument();
            catch (TransformerConfigurationException tce)
                System.out.println("Error during the parse :"+ tce.getMessageAndLocation());
            super.startDocument();
        public void startElement(String namespaceURI, String localName,
                String qualifiedName, Attributes atts) throws SAXException {
            handler.startElement(namespaceURI, localName, qualifiedName, atts);
            super.startElement(namespaceURI, localName, qualifiedName, atts);
        public void characters(char[] text, int start, int length)
                throws SAXException {
            handler.characters(text, start, length);
            super.characters(text, start, length);
        public void endElement(String namespaceURI, String localName,
                String qualifiedName) throws SAXException {
            super.endElement("", localName, qualifiedName);
            handler.endElement("", localName, qualifiedName);
        public void endDocument() throws SAXException {
        void endValidation() throws SAXException {
            handler.endDocument();
            try {
                TransformerFactory transfactory = TransformerFactory.newInstance();
                Transformer trans = transfactory.newTransformer();
                SAXSource sax_source = new SAXSource(new InputSource(new StringReader(meta_data_text.toString())));
                DOMResult dom_result = new DOMResult();
                trans.transform(sax_source, dom_result);
                meta_data = (Document) dom_result.getNode();
                System.out.println(meta_data_text);
            catch (TransformerConfigurationException tce) {
                System.out.println("Error occurs during the parse :"+ tce.getMessageAndLocation());
            catch (TransformerException te) {
                System.out.println("Error in result transformation :"+ te.getMessageAndLocation());
    } CreateXMLFile.java class :-
    Sax.startDocument();
    Sax.startValidation();
    Sax.startElement("", "pdf", "pdf", new AttributesImpl());
    Sax.startElement("", "basic-metadata", "basic-metadata", new AttributesImpl());          
    String xmp_str = new String(meta_data.getByteArray(),"UTF8");
    char[] xmp_arr = xmp_str.toCharArray();
    Sax.characters(xmp_arr, 0, xmp_arr.length);
    Sax.endElement("", "pdf", "pdf");
    Sax.endValidation();
    Sax.endDocument();
    Sax.endElement("", "basic-metadata", "basic-metadata");* In CreateXMLFile.java
    class, I have retreived the xml content in the meta_data object, after that i have converted into character array and this will be sends to SAX
    * In this case , the XML file created successfully but the retreived XML content added as an text in between basic-metadata Element, that is, retreived XML content
    is not an XML type text, it just an Normal text Why that ?
    * Please help me what is the problem in my code?
    Cheers,
    JavaImran

    Sax.startDocument();
    Sax.startValidation();
    Sax.startElement("", "pdf", "pdf", new AttributesImpl());
    Sax.startElement("", "basic-metadata", "basic-metadata", new AttributesImpl());          
    String xmp_str = new String(meta_data.getByteArray(),"UTF8");
    char[] xmp_arr = xmp_str.toCharArray();
    Sax.characters(xmp_arr, 0, xmp_arr.length);
    </code><code>Sax.endElement("", "basic-metadata", "basic-metadata");</code>
    <code class="jive-code jive-java">Sax.endElement("", "pdf", "pdf");
    Sax.endValidation();
    Sax.endDocument();     
    * I HAVE CHANGED MY AS PER YOUR SUGGESTION, NOW SAME RESULT HAS COMING.
    * I AM NOT ABLE TO GET THE EXACT OUTPUT.,WHY THAT ?
    Thanks,
    JavaImran{code}

  • SAX: How to create new XML file using SAX parser

    Hi,
    Please anybody help me to create a XML file using the Packages in the 5.0 pack of java. I have successfully created it reading the tag names and values from database using DOM but can i do this using SAX.
    I am successful to read XML using SAX, now i want to create new XML file for some tags and its values using SAX.
    How can i do this ?
    Sachin Kulkarni

    SAX is a parser, not a generator.Well,
    you can use it to create an XML file too. And it will take care of proper encoding, thus being much superior to a normal textwriter:
    See the following code snippet (out is a OutputStream):
    PrintWriter pw = new PrintWriter(out);
          StreamResult streamResult = new StreamResult(pw);
          SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance();
          //      SAX2.0 ContentHandler.
          TransformerHandler hd = tf.newTransformerHandler();
          Transformer serializer = hd.getTransformer();
          serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");//
          serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"pdfBookmarks.xsd");
          serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"http://schema.inplus.de/pdf/1.0");
          serializer.setOutputProperty(OutputKeys.METHOD,"xml");
          serializer.setOutputProperty(OutputKeys.INDENT, "yes");
          hd.setResult(streamResult);
          hd.startDocument();
          //Get a processing instruction
          hd.processingInstruction("xml-stylesheet","type=\"text/xsl\" href=\"mystyle.xsl\"");
          AttributesImpl atts = new AttributesImpl();
          atts.addAttribute("", "", "someattribute", "CDATA", "test");
          atts.addAttribute("", "", "moreattributes", "CDATA", "test2");
           hd.startElement("", "", "MyTag", atts);
    String curTitle = "Something inside a tag";
              hd.characters(curTitle.toCharArray(), 0, curTitle.length());
        hd.endElement("", "", "MyTag");
          hd.endDocument();
    You are responsible for proper nesting. SAX takes care of encoding.
    Hth
    ;-) stw

  • How to create an XML file from scratch ?

    Hi all,
    I'm afraid that I will seem dummy, but I think I really misunderstand something or I'm trying to do something that is not possible...
    I would like to create a XML file containing the following:<?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="pl.xsl"?>
    <!DOCTYPE playlist SYSTEM "pl.dtd">
    <playlist id="2">
    </playlist>I really need to have both the stylesheet and the DOCTYPE declarations... Does anyone know if this is possible ?
    To create the XML Document, I am using the DocumentBuilder object from javax.xml package (jaxp-1.2-ea2). I think this, at least, is correct.
    To print out the XML document I have tried to use :
    - the Transformer from javax.xml package (jaxp-1.2-ea2) but I could obtain only the DOCTYPE declaration.
    - the Serializer from Xerces parser (version 2.0.1) to print out the Document I am creating with the jaxp, but I was able only to obtain the stylesheet declaration...
    So far I have just understand that there is a difference between Serializer and Transformer (one is serializing, and the other is transforming ;-)), but I couldn't figure out which one would be suitable to produce the XML file above...
    I would really appreciate if one could help me with that ;-)
    Thanks,
    Karau

    Could send me an example ?
    For the moment I am using Transformer in that way:
         TransformerFactory tfactory = TransformerFactory.newInstance();
         try {
             Transformer transformer = tfactory.newTransformer();
             DOMSource source = new DOMSource(playlistDoc.getDocumentElement());
             StreamResult res = new StreamResult(new File(path));
             transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, PL_DTD);
             transformer.setOutputProperty(OutputKeys.INDENT, "yes");
             transformer.transform(source, res);
         catch (TransformerConfigurationException tce) {
             throw tce;
         catch (TransformerException te) {
             throw te;
         }

  • How to create an XML File Port in we21

    Hi firends,
    Can any one help me in creating the XML FILE PORT
    Its Urgent
    Thanks
    Ganesh

    Hi Ganesh,
    Directory
    The file is uniquely identified via the directory ("path") and their names.
    For IDoc files you may also use a "logical directory", which you assign in transaction FILE dependent on operating system "physical" directories.
    Outbound file
    There you can specify a fixed name for the file,
    Thanks
    Ravee..

Maybe you are looking for