aspose file tools*
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
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "convert Xml document to java Object" Watch "convert Xml document to java Object" New topic
Author

convert Xml document to java Object

BHAVESH SHA
Greenhorn

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);
Marshaller.marshal(doc1,writer);

it show error of:
(The filename, directory name, or volume label syntax is incorrect)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)


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



Thanks and Regards
Bhavesh Shah.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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.
JRaj
Greenhorn

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..
http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileWriter.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: convert Xml document to java Object