File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes java to xml how to ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "java to xml how to ??" Watch "java to xml how to ??" New topic

java to xml how to ??

madhu cm

Joined: Jun 26, 2005
Posts: 22
hello, i have some fields in swings apps like username and password...... so i need to generate an XML file using that file. can you please tell me how to generate an xml file?? which is better way to use either DOM or SAX ??

just i want to generate an xml doc from java source.....

help me, thank you
kirtikumar patel

Joined: Jun 29, 2005
Posts: 14
you can you xml schema for it.


kirti patel<br />software engiener<br />pune
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
There's a number of ways to do this.
DOM is a possibility (generate the DOM tree in memory and then serialize it to a file). If it's just a few elements like you suggest, you could just write the XML directly to a file. I've used XOM ( in the past to do this instead of DOM, but that's personal preference.
(SAX is an XML parsing method, so that isn't going to help you. XML schema is a description of the structure of an XML file, which won't do you any good either.)
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

Welcome to the JavaRanch, Madhu. We try to keep things friendly around here so we have a name policy. Basically we ask that everyone use a first name and a last name seperated by a space and not use a name that is obviously fake.
About your question, XML isn't as complex as it seems. It's just ASCII text with some markup around the data to indicate what the data is. There's tutorials on Java's API's for DOM and SAX in the J2EE Tutorial. DOM is usually used to manipulate an XML document and SAX is used to trigger events using an XML document (there's a more in depth discussion in the tutorial).
If you are just writing out a simple XML document, you may want to skip the API's and just write the markup and data to your output stream:

Note that XML must be "well formed", meaning every "open" tag (i.e. "<user>") must have a corresponding "close" tag (i.e. "</user>")

[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: java to xml how to ??
It's not a secret anymore!