| 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: 16483
|
|
|
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
|
 |
 |
|
|
subject: convert Xml document to java Object
|
|
|