Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

convert Xml document to java Object

 
BHAVESH SHA
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20764
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic