This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
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 Elasticsearch in Action this week in the Big Data 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: 19345

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..
I agree. Here's the link:
subject: convert Xml document to java Object