Writting XML

Posted on 2009-02-11
Medium Priority
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">abc@def.com</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

ID: 23617298
LVL 86

Accepted Solution

CEHJ earned 500 total points
ID: 23617357
LVL 92

Assisted Solution

objects earned 500 total points
ID: 23617363
theres an example here showing how to parse it:


let me know if you need any further help

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Assisted Solution

beekeep earned 500 total points
ID: 23617476
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

quincydude earned 500 total points
ID: 23618680
I think jdom would be your choice, it's a well known API for manipulating XML


Author Comment

ID: 23634101
Thanks all

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

I am sorry for the delay

Author Closing Comment

ID: 31545830
Many Thanks
LVL 86

Expert Comment

ID: 23648188

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month16 days, 7 hours left to enroll

864 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