Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: any better way for creating xml other than documentbuilder class??

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default any better way for creating xml other than documentbuilder class??

    Hi

    I want to create a small xml file by using some nodes out of a larger xml file.
    my approach:
    1. parse large xml file using sax parser
    2. select few nodes and instantiate a pojo class
    2. using documentbuilder to create xml with the data members of pojo class.

    (basically xml-to pojo-to xml)

    my question:
    any better way to do this???
    (dom takes up memory and this kind of feels repetitive )


  2. #2
    Junior Member
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default better ways creating xml other than using documentbuilder

    Hi
    (posted in wrong place initially )

    I want to create a small xml file by using some nodes out of a larger xml file.
    my approach:
    1. parse large xml file using sax parser
    2. select few nodes from this xml and setting the values into a pojo class
    2. using documentbuilder to create new xml getting data from the pojo class datamembers

    (basically xml-to pojo-to xml)

    my question:
    any better way to do this???
    (dom takes up memory and this kind of feels repetitive )

  3. #3
    Member
    Join Date
    Oct 2013
    Location
    Saint-Petersburg, Russia
    Posts
    33
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: any better way for creating xml other than documentbuilder class??

    Shortly speaking standard Java 7 API allows three approaches:

    - DOM (it is your documentBuilder);
    - SAX;
    - JAXB.

    The last is for direct mapping of pojos to XML and back with help of some annotations. You can easily find some tutorials if it is what you are looking for.

    To be honest, I prefer JSON since it could be mapped to objects straightly.

  4. #4
    Member
    Join Date
    Nov 2013
    Location
    Bangalore, India
    Posts
    70
    My Mood
    Cool
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default Re: any better way for creating xml other than documentbuilder class??

    As suggested JAXB is the easiest way provided you have a well defined schema for the xml to be parsed. As JAXB populates the nodes into POJO's. Please read tutorial on JAXB to proceed.

Similar Threads

  1. Creating a Custom Look(Skin): Synth/XML/SynthPainter
    By chronoz13 in forum AWT / Java Swing
    Replies: 0
    Last Post: November 7th, 2012, 05:36 AM
  2. Replies: 1
    Last Post: August 24th, 2012, 05:24 PM
  3. Creating and implementing class for creating a calendar object
    By kumalh in forum Object Oriented Programming
    Replies: 3
    Last Post: July 29th, 2011, 08:40 AM
  4. [SOLVED] Creating A Class
    By cb5950 in forum Object Oriented Programming
    Replies: 1
    Last Post: March 31st, 2011, 07:27 AM
  5. XML InputSource class and the retrieval/browser type
    By dave0110 in forum Object Oriented Programming
    Replies: 2
    Last Post: December 3rd, 2010, 09:11 AM