We help IT Professionals succeed at work.

Writting XML

tia_kamakshi
tia_kamakshi asked
on
Medium Priority
586 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

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
CERTIFIED EXPERT
Top Expert 2016
Commented:

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
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

Commented:
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

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

www.jdom.org

Author

Commented:
Thanks all

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

I am sorry for the delay

Author

Commented:
Many Thanks
CERTIFIED EXPERT
Top Expert 2016

Commented:
:-)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.