aspose file tools*
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
Author

java to xml how to ??

madhu cm
Greenhorn

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
Greenhorn

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


kirti


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

Joined: Mar 22, 2005
Posts: 42612
    
  65
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 (http://www.xom.nu/) 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.)


Ping & DNS - my free Android networking tools app
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9

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: http://aspose.com/file-tools
 
subject: java to xml how to ??