?
Solved

Writting XML

Posted on 2009-02-11
8
Medium Priority
?
567 Views
Last Modified: 2012-05-06
Hi,

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"?>
<!DOCTYPE eGAD SYSTEM "eGAD.Dtd">
<eGAD pakUID="PID_91962BD243A2A84F929CAA1BFD2018B4">
<jobdata>
<datetime>20070822152119</datetime>
<platform>Microsoft Windows</platform>
<Version major="4" minor="3"/>
<JobGUID>613A6B10FAE4794BB439EDBCF6F34A31</JobGUID>
<JobName>C:\Documents and Settings\user\Desktop\eMessaging\Folder_HTML\%2.html</JobName>
<JobShortName>%2.html</JobShortName>
<NativeFormat value="eHTML"/>
<ResourceGUID p="1" value="237853FCAEA44CE398F9043778C5AC61"/>
</jobdata>
 
 
<document docID="1" docMasterID="CF2A76BE175C691CC4693500D4048ED3" docInstanceID="A2AD25F4750A754491A2551CEEBFAC23">
<VendorId>a5f18288cc294573879357cd5a47451d</VendorId>
<DocTypeId>5865F1950EB14D028BA999AF5DADE524</DocTypeId>
<AccNo>PB485</AccNo>
<StmtDate>20070822</StmtDate>
<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>
<CustData>
<Name>Automobile Club of Southern California</Name>
<Addr line="1">3333 Fairview Rd Stop A454</Addr>
<City>Costa Mesa</City>
<Region>CA</Region>
<PostalCode>92626-1610</PostalCode>
</CustData>
<NumberOfPages value="2"/>
<Skipped><SPages></SPages></Skipped>
</document>
 
</eGAD>

Open in new window

0
Comment
Question by:tia_kamakshi
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 23617298
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 23617357
0
 
LVL 92

Assisted Solution

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

http://helpdesk.objects.com.au/java/how-do-i-create-a-dom-document-from-an-xml-file

let me know if you need any further help

0
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.

 
LVL 2

Assisted Solution

by:beekeep
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

0
 
LVL 15

Assisted Solution

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

www.jdom.org
0
 

Author Comment

by:tia_kamakshi
ID: 23634101
Thanks all

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

I am sorry for the delay
0
 

Author Closing Comment

by:tia_kamakshi
ID: 31545830
Many Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 23648188
:-)
0

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