?
Solved

problem with DOM

Posted on 2003-02-24
6
Medium Priority
?
177 Views
Last Modified: 2013-11-19
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
Comment
Question by:agusacil
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 8016333
What exactly are you attempting to do?
0
 
LVL 92

Expert Comment

by:objects
ID: 8037088
> 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
 
LVL 86

Accepted Solution

by:
CEHJ earned 80 total points
ID: 8037344
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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 4

Author Comment

by:agusacil
ID: 8039475
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 8040842
Is XmlDocument one of your classes or is it from someone else's library?
0
 
LVL 4

Author Comment

by:agusacil
ID: 8149776
Thank you very much. Sorry for waiting.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to dynamically set the form action using jQuery.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses
Course of the Month9 days, 20 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question