Generate XML file dynamically using java

Hi,
I searched on this topic on the net and also in this forum but everything leads to parsing an existing file using JAXP technology. But i need to create an xml file dynamically from the data coming from a different source. I can do it manually by writting the content to a file. But i am sure there is a better way for it. I would be obliged if some one could give me and example java class which produces a simple xml file or direct me to any resource online.
Thank you in advance.

Yes you can create the xml file dynamically. Like this,
BufferedWriter bw = new BufferedWriter(new FileWriter("xyz.xml"));
bw.write(buffer.toString()); //where buffer is StringBuffer whcih contains the your xml data
bw.close();
Remember to close the BufferedWriter, otherwise it will create the file but don't write anything.
Hope this will help u.
....yogesh

Similar Messages

  • How to create pdf files dynamically using Java

    I am new to java world. I got a task of generating dynamic pdf files using Java. I have tried with some third party APIs for generating pdf. But most of them are not so feasable. I am looking for source code for one such APIs so that I can build my custom requirements over it.
    Thanks

    I am new to java world. I got a task of generating
    dynamic pdf files using Java. I have tried with some
    third party APIs for generating pdf. But most of
    them are not so feasable. Which ones? What was wrong with them?
    I am looking for source
    code for one such APIs so that I can build my custom
    requirements over it.What are your exact requirement?

  • Generate XML file Dynamically

    We want to generate an xml file for the given folder in file system. This XML should contain nested nodes for all subfolders and files. Please could any one help me with logic to generate xml?
    Sample of XML
    <Parent_Folder>
    <Sub_Folder>
    <Sub_Sub_Folder/>
    </Sub_Folder>
    <Sub_File/>
    </Parent_Folder>
    Thanks in advance.

    Welcome to the Sun forums.
    1. Please post your code using code tags, this formats it so that it is easier for people to read and understand it. Click on 'CODE' above the text area when posting.
    2. As far as possible, please post an SSCCE
    3. Please explain what you are trying, what you're expecting and what you're getting. Don't expect to be spoon-fed the answer without putting in any work.
    The very simplest way would be to simply write all the nodes yourself:
    FileWriter writer = new FileWriter(new File("myXML.xml"));
    writer.write("<Parent_Folder>");
    writer.write("<Sub_Folder>");
    writer.write(subFolderFileObject.getName());
    writer.write("</Sub_Folder>");
    //etcBut this is pretty brittle and prone to errors and would only work for the most trivial files. If you want robust XML support then you should use some library like perhaps jdom

  • How to SaveAs the MSword file into xml file format using Java APIS?

    Hello all,
    I want to convert MSword file into Xml format using java APIS or any other inbuilt APIS that i can integrate in Java code.

    Sorry, that doesn't make much sense.
    The XML you gave is a configuration file for txt2xml utility. It doesn't represent the output format.
    Are you a user of this utility?

  • How to compare two huge xml files(50MB+) using Java Code

    I want to compare two huge xml files using java code and need to find the difference of those xml files
    is there any API for that

    You should find third party API

  • Generate PDF Files Dynamically Using XSL-FO

    Hi,
    I have downloaded the strutscx sample application and helped me lot in generting a PDF report and quite comfortable with that.
    But we have webapplication where in we dynmically need to generate a PDF report. But the data is really huge. So I have decided to write a offline to generate many PDF reports and save it to a file system. In the (struts)webapplication when I click on that link I will read that pdf file and display/open in browser. So basically I need to have all the .pdf files in the filesystem.
    Can somebody help me as to how to create and save a pdf file into filesystem using fop. Please help as this is really urgent for me.
    A sample code would be really helpfull for me.
    Kindly do the needfull.

    The information in this link:
    http://xmlgraphics.apache.org/fop/examples.html
    may be of some use to you. By the way, it was the first link that was returned when I put the keywords "fop examples" into Google. You might want to consider searching the web for information rather than waiting for personal service.

  • How to generate reportdesign dynamically using java with out xml file

    hi
    how can i generate a reportdesign dynamically using java with out passing xml file to jasperDesign , i want to create my reportdesign with out xml file
    how can i ,please help
    thanks

    LiveCycle does provide a Java API to forms; LiveCycle is in fact a suite of programs, mostly enterprise level for running on server (next to which the cost of the master suite is a drop in the ocean). LiveCycle Designer is perhaps the only end user tool, and it is not for server use and doesn't have an API.
    Are you looking for a server solution? If so, nothing in the master suite can help, it isn't for server use.

  • Using a data file in jsp to generate xml file

    hi
    can anybody help me to
    how to use a data file generated in unix in jsp to generate xml file.
    by using beans i am able to generate the xml.
    thanks in advance.

    You haven't provided adequate relevant information. If you need help provide proper relevant details.

  • How to generate XML file using select files manually option in MOPz

    Hi Guru's!
    Can someone tell me how can I generate XML file not using the calculate automatically option but using select files manually. thanks!

    Hi Maix,
    You may manually add the files into download basket and then approve it.
    Use the SCN document below for the steps.
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/10b14f0c-b9af-2e10-ba83-f05ebcfbc3c2?QuickLink=index&…
    Hope this helps.
    Regards,
    Deepak Kori

  • How to Read and Generate XML file from java code.

    hi guys,
    how to read the xml file (Condition :we know only DTD or Shema only).
    How to Generate the new xml file ?(using Shema )
    And one more how directly Generate the xml from DB?
    Pleas with code or any URL

    Using XMLbeans you can generate Java objects from an XSD schema (perhaps DTDs aswell)
    Then you can create an instance of the Document object and ask it to write itself.
    This will create an XML document complient to the schema.
    XMLBeans generates a "type" safe DOM where you can only ever have a structure compilent to you schema.
    matfud

  • XSLT, using document() to fetch a local JSP generated XML file

    All,
    I have 1 XML document that keeps track of various subsite owners of a domain I manage. The xml file doesn't hold much, something along the lines of:
    <?xml version="1.0"?>
    <sitedirectory>
         <page id="/marys_page" name="Mary's Page"">
              <content_contact ntid="smithm" />
              <technical_contact ntid="techguy" />
         </page>
    </sitedirectory>Now I also have a JSP page, that when given an NT id as a URL parameter, rifles through LDAP and spits out an xml document with all the relavent ISID fields for that person's id (first name, last name, phone number, e-mail address etc).
    I use the document() function in an XSL file to access that dynamic JSP page, fetch the contents of the resulting XML file. Using the document() function with just a regular file call like "getldap.jsp" only feeds my stylesheet the source of that JSP file, not the resulting XML file that I'm looking for when it's been processed.
    So... I have my document() function calling the full URL to that JSP file on my domain, an example <value-of /> call in my XSL file would be:
    <xsl:value-of select="document('http://my.domain.com/jsp_util/ldap_person.jsp?ntid=smithm')/person/firstname" />and I get what I want, that person's first name, drawn from LDAP into my XSL file. But it seems a little weird to me, having a server-side transformation, accessing a JSP file by making an http call to the same server the transformation resides in.
    Am I missing something? Is there a better way to do this or some directive I'm missing? I'd appreciate any help.

    That's a creative but perfectly reasonable way to use the document() function.
    There are other ways to solve the problem, such as including Java calls in your XSL and applying a customized URIResolver to your transformation, but my approach would be to use the simplest method that works acceptably. So if you don't have performance problems with your solution, I would leave it alone.

  • How to send the dynamically generated XML file to other site for further processing?

    I have a question regarding exchanging data between two systems
    using XSQL servlet. The situation is descrbed as the follows:
    Assume that we have a simple XSQL page named "emp.xsql"
    <?xml version="1.0"?>
    <?-- XSQL page file "emp.xsql" -->
    <xsql:query xmlns:xsql="urn:oracle-xsql" connection="demo" >
    SELECT * FROM EMP
    </xsql:query>
    and we can access it through the HTTP request likes
    http://web_server_name/xsql/emp.xsql.
    Usually we will the returned dynamic XML file and show it on the
    screen. Now the problem is that we don't want to show the
    generated XML file on the calling screen. Instead, we want to
    send the generated XML file to other website for further
    processing, say, using JSP or ASP likes
    http://other_web_server_name/XMLProcessing.jsp?.....
    How can it be implemented using XSQL servlet?
    Any hint and outline of the solution is appreciated.
    Thanks

    Ike,
    Do you have a sample. I am searched so much in this forum for samples. I looked on SAX Parser. I did not find any samples.
    Please help me.
    Thank you for your posting.
    Padma.

  • Java code to generate XML File from XML Schema

    Hi I need this asap... "Java code to generate XML File from XML Schema i.e XML Schema Definition, XSD file".
    Thankz in advance...

    JAXB has been available as an early release download for some time. There are also XML Binding packages available from Borland (JBuilder) and Castor. These tools create Java classes from a source document, xml,dtd etc. You can use these classes to marshal-unmarshal XML documents.
    Dave

  • Using servlet to generate XML file

    What I want to do is simple but can't work. Hope you guys can give me a hint.
    I succesfully generate XML file in command line using Oracle XML parser and class generator. Then I was trying to do it using servlet. it compiles fine but generate NullPointer exception at the line:
    Emp e1= new Emp(); //Emp is the root of XML
    I suspect the Emp constructor can't correctly find the globalDTD in its superclass -CGDocument. Please note this only happens in servlet setting, not is command line setting. Any suggestion to get arounf this?
    Another unrelated question is that when I create a XML file using the Oracle XML parser, it seems all the elements a file has to be added once, otherwise the compiler will compalain about the missing element. this will be inconvinient when I constructing a big XML file, which I 'd liek to split into small piece and add them up. Maybe there is a good way but I just don't know it.
    my email: [email protected]

    Hi,
    I'm running into the same problem deploying the classes generated by the class generator. Code works fine from JDeveloper, but had to put my DTD in the directory where my classes are. Deploying the classes with Apache's JServ gives me a NullPointer exception on the first addNode method. I guess it can't find the DTD. I tried to put the DTD in many locations but this didn't fix the problem. Any suggestions?
    Steve,
    Did you fix this problem? Thanx!
    null

  • Generate XML file from RFC using Web Services

    Hi,
      I am trying to save an RFC enabled Function Module output to an XML file using ABAP web services.
    I could able to create Web Service and release it using WSCONFIG/WSADMIN. I can actually get the output in XML file when i launch the web service home page. But I need this to be done in the ABAP program itself. So If i run the RFC I could able to create,release web service and capture the Generated XML file by SOAP runtime.
    Any FM available?
    Thanks,
    Ram Sanjeev

    which version of WAS you are on .
    if you are on WAS6.40 check the following weblog on how to consume webservice using the wsdl file.
    /people/thomas.jung3/blog/2004/11/17/bsp-a-developers-journal-part-xiv--consuming-webservices-with-abap
    lower version of WAS use class cl_http_client.
    if this case you have to manually build the soap message.
    /people/durairaj.athavanraja/blog/2004/09/20/consuming-web-service-from-abap
    Regards
    Raja

Maybe you are looking for