aspose file tools*
The moose likes XML and Related Technologies and the fly likes XML : how to parse effectively ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML : how to parse effectively ?" Watch "XML : how to parse effectively ?" New topic
Author

XML : how to parse effectively ?

Marat Matosov
Greenhorn

Joined: Sep 25, 2002
Posts: 6
Hello Dear Sirs !
I am a newbie in XML world and I need to parse and also write to file yhe next XML Format :
<FORMAT NAME="InputQG30Format">
<TransactionCode>QG30</TransactionCode>
<FunctionKey>00</FunctionKey>
<ProcessType>O</ProcessType>
<PreformattingIndicator>no</PreformattingIndicator>
<InputFormat>
<F VALUE="USER">USERCtx</F>
<F VALUE="PSWD">PSWDCtx</F>
<F VALUE="NEWPSWD">NEWPSWDCtx</F>
<F VALUE="VNPSWD">VNPSWDCtx</F>
</InputFormat>
</FORMAT>
But I have no idea how i can do that ? I will very appretiate your attempt to help me .
How i can parse it ? What is the better parser for this case ? Each clue and code snippet will be properly appretiated .
Thank you ,

Marat
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Hi,
You can parse it using different methods,
1.Java with Xerces or crimson
2.XALAN with XSLT
3.ASP with MSXML
4. ......
1.If you want to write a java code to parse the input XML you can read this tutorial and try
using DOM orUSing SAX These two tutorials will give you some basics ideas on how to parse the xml. You can download either Xerces or Crimson as Parser, I found Crimson is faster.
2.you can write XSLT to convert the inputXML in to any format you want.You have to learn XSLT which is relatively easy.(don't have good tutorial links now,will give you on monday). But the XML tutorials at this link http://www.w3schools.com/ and the XML Processing tutorials will sure help you,the former will teach you the fundas of XML.
3.OR download MSXML from MS site ,after installing double click MSXML help from your desktop,you will get bunch of tutorials to parse xml using asp,vb,js,vbscript etc.,
[ December 22, 2002: Message edited by: Balaji Loganathan ]

Spritle Software Blogs
Channy
Greenhorn

Joined: Nov 18, 2002
Posts: 13
Not everybody here is a sir that can help you out.
FormatName fn = (FormatName)u.unmarshal(xmlFile);
FormatName tempfn = ObjectFactory.createFormatName();
TransactionCode tc = ObjectFactory.createTransactionCode();
tc.setValue("QG30");
etc.
....
Marshaller m = jc.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
m.marshal(tempfn, xmlOutFile);
If you're interested in using java objects created from the xml, and are more comfortable with Java, using JAXB might help you.
http://java.sun.com/xml/jaxb/
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: XML : how to parse effectively ?