problem with DOM

Posted on 2003-02-24
Medium Priority
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 :

     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 ?

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

Expert Comment

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

Expert Comment

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.
LVL 86

Accepted Solution

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);
catch(Exception e) {
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.


Author Comment

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.
LVL 86

Expert Comment

ID: 8040842
Is XmlDocument one of your classes or is it from someone else's library?

Author Comment

ID: 8149776
Thank you very much. Sorry for waiting.

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