IBM XML4J Question

Posted on 2000-05-02
Last Modified: 2012-06-27
I have just downloaded and installed the IBM parser and performed a successful installation test.  When I attempt to run the following code I receive an error.  Can anyone tell me why?

import org.apache.xerces.parsers.DOMParser;

public class TESTXML {

public static void main (String args[]) {
    Document doc;
    Parser p = new Parser("XMLParser");
    try {
       FileInputStream file = new FileInputStream(Document);
       doc = p.readStream(file);
     catch ( e) {

ERROR: Class Parser not found in type declaration.
    Parser p = new Parser("XMLParser");

Can someone provide me with a simple example of how to parse a value from an XML file?
Question by:ubsjmg
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

Accepted Solution

yanchou earned 100 total points
ID: 2771425
Hmmm..., it looks like you are using xerces instead of IBM XML4J.

change the error line to

DOMParser p = new DOMParser(".....");



Expert Comment

ID: 2771525
BTW, Parser is an interface that SAXParser and DomParser implements. Parser know nothing about Document. If you download use XML4J. There should be  enough examples come with the zip files

Expert Comment

ID: 2771543
Here is the example for xerces:

      import org.w3c.dom.Document;
      import org.apache.xerces.parsers.*;
         * This code tests your classpath.
      public class cptest
        Document doc = null;
        DOMParser parser = new DOMParser();
        /** Main program entry point. */
        public static void main(String argv[])
          System.out.println("If you see this message, everything is okay!");
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 2771759
I actually figured that out after I submitted the question.  I apologize and will increase the points if you can help me further.  When I attempt to compile the following code I receive the following errors.

import org.w3c.dom.*;

public class testxml {
   public static void main(String args[]){
         TXElement e;
         Parser p = new Parser("XMLParser");
         System.out.println("Parser Created");

ERROR: Package not found in import.
       ^ Package org.w3c.dom not found in import.
import org.w3c.dom.*;
2 errors              

I have my classpath pointing to the xml4j.jar file.  Do you have any ideas why the compiler can't find the packages?  I am using JDK1.1.6 on AIX.  Thanks in advance.

Expert Comment

ID: 2785769
I have used the IBM parser on NT platform without any problems.
However I have heard ( not sure if it is true) that IBM platforms are picky about the order of class paths. Try moving the xml4j.jar file to the head of the classpath and give it a try.

Good luck


Author Comment

ID: 2865561
Answer accepted

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SHA2 certs for IIS AND Java? 2 136
login form jsp example 2 71
Is there a simpler dropbox system? 10 53
What does this method description mean? 1 14
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

739 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