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.....
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.)
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>")