Construct XML files in Java

Hi,
Can you any give me some third party libraries widely used to create XML file out of trading information ?
Thanks

XML handling has been available in core Java since v1.4.
But if you stick to a third party library, JDOM is fine.
  private static String transform( org.w3c.dom.Document doc ) throws Exception
    javax.xml.transform.TransformerFactory      tf = javax.xml.transform.TransformerFactory.newInstance();
    javax.xml.transform.Transformer             t = tf.newTransformer();
    javax.xml.transform.Source                  source = new javax.xml.transform.dom.DOMSource( doc );
    java.io.StringWriter                        sw = new java.io.StringWriter();
    javax.xml.transform.Result                  result = new javax.xml.transform.stream.StreamResult( sw );
    t.setOutputProperty( javax.xml.transform.OutputKeys.ENCODING, ENCODING );
    if ( OMIT_XML_DECLARATION )
      t.setOutputProperty( javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes" );
    t.transform( source, result );
    String      ret = sw.toString();
    return ret;
}

Similar Messages

  • Generation of xml file from java code

    hi,
    I want to manipulate data in a xml file with java code.I have read data from xml file and also changed it. But i am unable to covert it again in xml file from java code. Can you please tell me how i can do this?

    Let me know which parser are you using currently for reading xml files so that i assist you. For now, you can refer to STAX Parser API under this link
    http://java.sun.com/webservices/docs/1.6/tutorial/doc/SJSXP3.html

  • How to read the data from Excel file and Store in XML file using java

    Hi All,
    I got a problem with Excel file.
    My problem is how to read the data from Excel file and Store in XML file using java excel api.
    For getting the data from Excel file what are all the steps i need to follow to get the correct result.
    Any body can send me the code (with java code ,Excel sheet) to this mail id : [email protected]
    Thanks & Regards,
    Sreenu,
    [email protected],
    india,

    If you want someone to do your work, please have the courtesy to provide payment.
    http://www.rentacoder.com

  • How to edit the existing data in the XML file from java programming.

    Hi all
    i am able to create XML file with the sample data as below from java programming.
    i need sample code on how to edit the existing data in the XML file?
    for example
    <?xml version="1.0"?>
       <mydata>
               <data1>
                         <key1>467</key1>
                        <name1>Paul</name1>
                        <id1>123</id1>
              </data1>
              <data2>
                         <key2>467</key2>
                        <name2>Paul</name2>
                        <id2>123</id2>
              </data2>
        </mydata>
    i am able to insert the data in the XML.
    now i need sample code on how to modify the data in the above XML file from the java programming for only key2,name2,id2 tags only. the remaining tags data in the XML file i want to keep same data except for key2,name2,id2 which are i want to modify from java code
    Regards
    Sunil
    [points will be always rewardable]

    hi
    u need a parser or validate the xml file for to read the xml file from java coding u need for this
    xml4j.jar u can download this file  from here
    http://www.alphaworks.ibm.com/tech/xml4j
    or we can use the SAX(simple API for XML)
    some sample applications for this
    http://www.java-tips.org/java-se-tips/javax.xml.parsers/how-to-read-xml-file-in-java.html
    http://www.developertutorials.com/tutorials/java/read-xml-file-in-java-050611/page1.html
    http://www.xml-training-guide.com/e-xml44.html
    let me know u need any other info
    bvr

  • 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

  • Create XML file from java

    Hi all i am working to create a XML file using java can any one show me some sample code how to do so

    All I suggested was to insert a single line ("X.serialize(root);") into your code. Anyway, here's a ready-to-compile source code based on yours. This code utilizes the Xerces-J class library.import java.io.File;
    import java.io.FileWriter;
    import org.apache.xerces.dom.DocumentImpl;
    import org.apache.xml.serialize.OutputFormat;
    import org.apache.xml.serialize.XMLSerializer;
    import org.w3c.dom.Element;
    public class Test {
      public static void main(String[] arguments) {
        FileWriter out;
        DocumentImpl d;
        Element root;
        XMLSerializer X;
        try {
          System.out.println(" creatin ");
          File fos = new File("xsr.xml");
          out = new FileWriter("xsr.xml");
          System.out.println("created File .." + fos.getName());
          out.flush();
          d = new DocumentImpl();
          System.out.println("create root");
          root = d.createElement("abc");
          System.out.println("creating element");
          d.insertBefore(root, null);
          //out.write(d.createAttribute(""));
          OutputFormat o = new OutputFormat(d);
          System.out.println("Output format...");
          o.setIndent(5);
          o.setIndenting(true);
          o.setDoctype("lab1.dtd", "lab1.dtd");
          o.setDoctype("name of dtd file", "name of dtd file");
          X = new XMLSerializer(o);
          X.setOutputCharStream(out);
          X.serialize(root);
          out.flush();
          out.close();
        catch (Exception e1){
          e1.printStackTrace();
    }

  • Creating XML file from Java Bean

    Hi
    Are there any standard methods in Java 1.5 to create XML file from java bean,
    i can use JAXB or castor to do so,
    But i would like to know if there is any thing in java core classes,
    I have seen XMLEncoder, but this is not what i want.
    Any ideas
    Ashish

    Marshall JavaBean to an XML document with JAXB or XMLBeans.

  • How to modify an existing xml file from java code.

    Hi
    I have worked on creating a new xml file from java code using xmlbeans.But if i try to modify an already existing file using java code I am unable to get errorfree xmlfile.
    For example if xml file(studlist.xml) is as below:
    <?xml version="1.0" encoding="UTF-8"?>
    <StudentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\kchaitanya\xmlprac1\abc\Studlist.xsd">
         <Student>
              <Name>ram</Name>
              <Age>27</Age>
         </Student>
    <Student>
              <Name>sham</Name>
              <Age>26</Age>
         </Student>
    </StudentList>
    Now suppose i have set name to victor using student.setName,
    and set age to 20 using setAge from javacode,
    the new xml file is as follows:
    <?xml version="1.0" encoding="UTF-8"?>
    <StudentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\kchaitanya\xmlprac1\abc\Studlist.xsd">
         <Student>
              <Name>ram</Name>
              <Age>27</Age>
         </Student>
    <Student>
              <Name>sham</Name>
              <Age>26</Age>
         </Student>
    </StudentList>
    <Student>
              <Name>victor</Name>
              <Age>20</Age>
         </Student>
    As observed this is not a valid xml file.But how can i modify without any errors?

    I know it's an old post, but I found this while doing a google search for something else, and don't like to leave it un-aswered
    Just in case anyone has a similar problem... In this case the new elements have been appended outside of the root element
    What you need to do is first get the root element and then append the new children to that, there are several ways of getting the root element, which depend on what you want to do with the elements you get back here's a simple (incomplete) way.
    // gets the root element of the specified file (code not shown)
    Element rootElement= new SAXReader().read(file).getRootElement();Then just append the new elements as below (this is non-generic code and would need to be modified for your situation)
    // write a new student element
    Element student = document.createElement("Student");  // creates the new student
    rootElement.appendChild(student); // ***appends it to the root element***
    Element name = document.createElement("Name"); // creates the name element
    name.appendChild(document.createTextNode("Fred")); // adds the name text to the name element
    student.appendChild(name); // appends the name to the student
    Element age= document.createElement("Age"); // creates the age element
    age.appendChild(document.createTextNode("26")); // adds the age text to the age element
    student.appendChild(age); // appends the name to the studentThen flush ya buffers or whatever and write the file
    Edited by: Dream-Scourge on Apr 23, 2008 11:10 AM

  • How to write as XML file using java 1.5

    hi all,
    i am trying to create an XML file using java 1.5. I took a XML creating java file which was working with java 1.4 and ported same file into java 1.5 with changes according to the SAX and DOM implmentation in java 1.5 and tried to compile. But while writing as a file it throws error "cannot find the symbol."
    can any body help me out to solve this issue.......
    thankx in advance
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.w3c.dom.NamedNodeMap;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import org.xml.sax.DocumentHandler;
    import org.xml.sax.InputSource;
    import org.xml.sax.helpers.ParserFactory;
    import java.io.*;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();                   
                   dbf.setNamespaceAware(true);
    DocumentBuilder db = dbf.newDocumentBuilder();                   
    Document xmlDoc =  db.newDocument();
    // this creates the xml document ref
    // parent node reference
    Element rootnd = (Element) xmlDoc.createElement("ALL_TABLES");
    // root node
    xmlDoc.appendChild(rootnd);
    Element rownd = (Element) xmlDoc.createElement("ROW");
    rootnd.appendChild(rownd);
    Element statusnd = (Element) xmlDoc.createElement("FILE_STATUS");
    rownd.appendChild(statusnd);
    statusnd.appendChild(xmlDoc.createTextNode("Y")
    FileOutputStream outpt = new FileOutputStream(outdir + "//forbranch.xml");
    Writer outf = new OutputStreamWriter(outpt, "UTF-8");
    //error is occuring here Since write method is not available in the Document class
    xmlDoc.write(outf);
    outf.flush();

    Hi,
    when I look in the JDK1.4.2 specification I don't see any write method in the Document interface.
    However, your solution is the Transformer class. There you transform your DOM tree into any output you need. Your code sould look something like this:     TransformerFactory tf = TransformerFactory.newInstance();
         // set all necessary features for your transformer -> see OutputKeys
         Transformer t = tf.newTransformer();
         t.transform(new DOMSource(xmlDoc), new StreamResult(file));Then you have your XML file stored in the file system.
    Hope it helps.

  • Accessing XML files through java

    Can any one explain me the easiest way of accessing XML files from Java.

    Hi,
    If you want to only access the XML file, use the SAX parser It will be very easy to handle and identify the element and value.
    else if u want to change the XML value also, then better go with DOM, Which has very good flexiblity.
    use according to the need, let me know if any help is required......
    With Cheers
    PrasannA

  • Merging 2 message history xml files using java

    hi., i'm new to xml programming..
    well..., i got homework bout it..., and got a lot of problems to write it..
    could you help me a favor??
    I need to write a homework bout merging 2 MSN mssg history files (xml files) using java.
    At least need to maintain their date, time, sender, receiver, and information(sayings)....and are ordered using time..
    can u help me??

    Well, show us what you've got and where you are having difficulty.

  • How to read XML files from java

    i need a sugession that how to read a xml file using java code
    and i need to parse using some parsers and display attributes and entity seperately
    as a string.......

    import org.dom4j.Document;
    import org.dom4j.DocumentException;
    import org.dom4j.io.SAXReader;
    import java.io.File;
    import java.text.AttributedCharacterIterator.Attribute;
    import java.util.Iterator;
    import java.util.StringTokenizer;
    public class XmlParser
    private String Result="";
    private String Final="";
    private String Delim="";
    public void bar1(Document document) throws DocumentException
    org.dom4j.Element root = document.getRootElement();
    // System.out.println(root.getName());
    bar2(root);
    System.out.println(this.Result);
    process();
    public void bar2(org.dom4j.Element e)
    for(Iterator i = e.elementIterator();i.hasNext();)
    org.dom4j.Element Element = (org.dom4j.Element) i.next();
    Result += Element.getName()+"\t"+Element.getText()+"\n";
    bar2(Element);
    public void process()
    StringTokenizer Tokenizer = new StringTokenizer(this.Result,"\n");
    String element;
    while(Tokenizer.hasMoreTokens())
    element = Tokenizer.nextToken();
    StringTokenizer Tokenizer2 = new StringTokenizer(element,"\t");
    // Do what ever String Process here Example
    this.Final += element.getName();
    this.Final += this.Delim;
    System.out.println(this.Final);
    public static void main(String s[])throws Exception
    Document document = null;
    SAXReader reader = new SAXReader();
    File f1= new File("D:/Rajesh/EDI to XML/EDI.xml");
    document = reader.read(f1);
    Demo obj = new Demo();
    obj.bar1(document);
    i think this will hep full.......

  • Passing Parameters from XML file to Java Application

    Can any one help me to know the way of passing values from XML file to Java Application..
    Thanx in advance

    With the Processing Instructions <?name pidata?>
    Get the Nodes in a Document.
    Node node;
    if(node.getNodeType()==Node.PROCESSING_INSTRUCTION_NODE)
    //String param=node.getData();

  • The nicest way to generate xml-files by Java???

    I have to generate huge and quite complex xml files by Java. I have to fetch the data from a Oracle database. What I really don't know is a proper and reliable way to this? I could of course create a String and concatenate all the tags, attributes and data but it doesn't feel right. I guess this is a quite common task and there are many established ways to this by Java. My question is what is the best way to this? What is your suggestion?
    Thank you for any clues...

    Hi,
    Since you have access to the database, I think one of the best way is to create stored procedures that will generate those files for you (using SQL/XML functions preferably) and return the content to the Java caller.

  • Do i required to generate XML file for JAVA upgrade.

    Dear frnds,
    I am in process of upgrading EP 6.0 to  EP 7.0 EHP1 for SR1.
    I am following document   Upgrade Guide SAP NetWeaver 7.0 Java Including Enhancement Package 1
    As of media list guide i have selected .
    51036889_1/2 for UPG MASTER BS7 SR1
    51037093_1,2,3 for NW 7.0 EHP1 SR1 java SW components 1/2
    51036767_2 for BS7 UC kernel 7.01 AIX 64 bit.
    Well, i have a query here when i am doing upgrade on ABAP stack ECC 5.0 to ECC 6.0 EHP4 SR1  i alowed to select required compoenets , which eventually will generate mea XML file in Solution manager system.
    But, When i have planned to UPGRADE only  JAVA Stack for EP 6.0 to EP 7.0 EHP1 SR1.  When i selected my system in Solution manager i am not getting option for UPGRADE.
    If it is so how about my XML file  during JAVA upgrade is not mandatory or not .. Please advice me on this.
    regards,
    rahul

    Hi Rahul,
    Yes, for Java Upgrade to EHP1 you need xml file. Normally you should be able to download xml file from solution manager from MOPZ.
    If you are not able to download it from solman then you can also download the xml file from service market place and this is only for EHP1.  Follow below procedure to download xml file from SMP for EHP1:
    Go to https://websmp205.sap-ag.de/sp-stacks
    Click on SP Stack download.
    Select SP Stack Netweaver 7.0 (New window will open)
    Then on New Window Select Source Stack, Target Stack and usgae type. Then Click Next.
    On Next screen Select Kernel and IGS. Then Go Next.
    On that screen you will get a option to Save as File. Then save as xml.
    This is the xml file that you can use in upgrade.
    For EHP4 you cannot download it from service market place.
    Thanks
    Sunny

Maybe you are looking for

  • Open file from table with double click

    Hi all, I use adf faces and JDEV 11. I want to open a file by double clicking on row in a table. (file is stored in the database). I first tried it with a button to open the file, with this code:        System.out.println("Double click!");           

  • How can we transfer the date field in to the PO in R/3 from SRM

    Hi, We are using classic scenario with SRM release 5.50 and when we create SC using service option we can maintain the delivery date with start and end date in SC. In R/3 ECC 5.0 when the SC is converted as PO the end date is not reflected as we are

  • How to find the user exits and BADIS from SPRO

    Hi all, please let us know how to find the User exits or BADIS for an application from SPRO. Regards, Madhavi

  • Word 2007 Crashes

    Every time I open Word 2007 it crashes. It also crashes while working in a document.  Any help you can provider would be greatly appreciated.  It is getting very frustrating. The following is the error message pops up: Word has stopped working .....

  • Oracle E-Business Suite access from the Host machine

    Hellow, Please, after installing E-Business Suite and going through Post-configuration details, I would like to get access of my applications portal from the host system. I have tried several ways of doing that and would not know the steps to follow