• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

problem with DOM

I code an XML app such this ( I took this from Deitel's book example ) :
........//code to create a DOM
               
( (XmlDocument) document).write( new FileOutputStream( "intro.xml" ));

.........//code to catch exception

And I got this runtime exception :

java.lang.ClassCastException
     at ReplaceText.<init>(ReplaceText.java:49)
     at ReplaceText.main(ReplaceText.java:66)

XmlDocument class is the child of Document class, but why this exception occured ?

0
agusacil
Asked:
agusacil
  • 3
  • 2
1 Solution
 
CEHJCommented:
What exactly are you attempting to do?
0
 
objectsCommented:
> but why this exception occured ?

Because you are attempting to cast an object to a subclass of which it is not an instance.

If that is line 49 you posted above then the reason is that document is not an instance of XMLDocument.
0
 
CEHJCommented:
If you're trying to write the document to that xml file and you're using JDOM (implied), try:

try {
     org.jdom.output.XMLOutputter outputter = new org.jdom.output.XMLOutputter();
     java.io.FileOutputStream out = new java.io.FileOutputStream("intro.xml");
     outputter.output(document, out);
     out.close();
}
catch(Exception e) {
     e.printStackTrace();
}    
 
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
agusacilAuthor Commented:
XmlDocument is a class that implements another class which extends Document class.
Exactly I want the xml document to be manipulated as a data source in jakarta tomcat server. For example I want an employee xml document to be read and write in the server by internet browser

Do you have any idea of performing this ?

any help would be appreciated.
0
 
CEHJCommented:
Is XmlDocument one of your classes or is it from someone else's library?
0
 
agusacilAuthor Commented:
Thank you very much. Sorry for waiting.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now