Writting XML

Posted on 2009-02-11
Last Modified: 2012-05-06

I am working in Java after a long time.
Can any one help me in creating below pasted XML
If someone has some class, which i can use directly for reading and writting would be great

Many Thanks
<?xml version="1.0" encoding="UTF-8" standalone="no"?>


<eGAD pakUID="PID_91962BD243A2A84F929CAA1BFD2018B4">



<platform>Microsoft Windows</platform>

<Version major="4" minor="3"/>


<JobName>C:\Documents and Settings\user\Desktop\eMessaging\Folder_HTML\%2.html</JobName>


<NativeFormat value="eHTML"/>

<ResourceGUID p="1" value="237853FCAEA44CE398F9043778C5AC61"/>


<document docID="1" docMasterID="CF2A76BE175C691CC4693500D4048ED3" docInstanceID="A2AD25F4750A754491A2551CEEBFAC23">





<DDSDocValue name="Email" type="text" len="19"></DDSDocValue>

<DDSDocValue name="Subject" type="text" len="37">Software Maintenance Reminder</DDSDocValue>

<DDSDocValue name="AttachName1" type="text" len="19">Group1 Reminder.pdf</DDSDocValue>

<DDSDocValue name="AttachName2" type="text" len="13">Somename2.pdf</DDSDocValue>

<DDSDocValue name="AttachName3" type="text" len="13">Somename3.pdf</DDSDocValue>

<DDSDocValue name="MSISDN" type="text" len="11">00000000000</DDSDocValue>

<DDSDocValue name="Expiry" type="text" len="8">20090820</DDSDocValue>


<Name>Automobile Club of Southern California</Name>

<Addr line="1">3333 Fairview Rd Stop A454</Addr>

<City>Costa Mesa</City>




<NumberOfPages value="2"/>




Open in new window

Question by:tia_kamakshi
    LVL 86

    Expert Comment

    LVL 86

    Accepted Solution

    LVL 92

    Assisted Solution

    theres an example here showing how to parse it:

    let me know if you need any further help

    LVL 2

    Assisted Solution

    I'm know I'm just repeating info you could find by referencing all the other links, but here are some nicely encapsulated methods that I use all the time.  Depending on your preferred style, you may not agree with my preference for recasting various exceptions into unchecked RuntimeExceptions..  That's fine -- you can always strip out the "catch" clauses and replace them with "throws" declarations in the method headers.

    One quick note:  There are versions of the APIs that would allow you to parse from a Reader or print to a Writer.  *** Don't use them. ***  It is entirely too easy to end up with the printer/parser trying to deal with a different character encoding than the Reader/Writer is using, and thus end up with unparseable gibberish.  By using Streams instead, you can let the Parser/printer deal with all the encoding issues, and everything will work out as you desire.

      static public Document parseToDOM(final InputStream in) {
        try {
          final DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
          return fact.newDocumentBuilder().parse(in, null);
        } catch (final SAXException ex) {
          throw new RuntimeException(ex);
        } catch (final IOException ex) {
          throw new RuntimeException(ex);
        } catch (final ParserConfigurationException ex) {
          throw new RuntimeException(ex);
      static public void printDOM(final OutputStream stream, final Node dom, final boolean noHeader) {
        try {
          final TransformerFactory fact = TransformerFactory.newInstance();
          final Transformer trans = fact.newTransformer();
          if (noHeader)
            trans.setOutputProperty("omit-xml-declaration", "yes");
          trans.setOutputProperty("indent", "yes");
          trans.setOutputProperty("encoding", "utf-8");
          final DOMSource from = new DOMSource(dom);
          final StreamResult to = new StreamResult(stream);
          trans.transform(from, to);
        } catch (final TransformerException ex) {
          throw new RuntimeException(ex);

    Open in new window

    LVL 15

    Assisted Solution

    I think jdom would be your choice, it's a well known API for manipulating XML

    Author Comment

    Thanks all

    I will come back to you. I am working on it.

    I am sorry for the delay

    Author Closing Comment

    Many Thanks
    LVL 86

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
    This video teaches viewers about errors in exception handling.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now