File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes convert Xml document to java Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "convert Xml document to java Object" Watch "convert Xml document to java Object" New topic

convert Xml document to java Object


Joined: Jun 07, 2007
Posts: 15
Dear Sir,

I am try to convert my xml Document to java Object using castor ,but cannot do it ,

code :
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
org.w3c.dom.Document doc1 = db.newDocument();
String xml="<Application><applicants><applicantID>3423</applicantID> </applicants> </Application>";

doc1 =db.parse(new InputSource(new StringReader(xml)));
FileWriter writer = new FileWriter(xml);

it show error of:
(The filename, directory name, or volume label syntax is incorrect)
at Method)

kindly advise for the same or alternative option rather than caster.

Thanks and Regards
Bhavesh Shah.
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

Let's look at a fragment of your code:That line suggests that "xml" is a String variable, and its contents are some XML that you want to parse.That line suggests that "xml" is a String variable, and its contents are the name of a file you want to write data to. It's unlikely that both of those are true. Something is wrong with one of those two lines.

Joined: Mar 13, 2008
Posts: 3
See the java API for FileWriter class, it take String file names..and you have given XML data as he file name..check it out..
Consider Paul's rocket mass heater.
subject: convert Xml document to java Object