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
  • 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!");
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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


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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTTPSessionBindingListernter not configured in deployment descriptor 2 65
egit plugin on eclipse 8 82
fibonacci ten numbers 4 45
jmss example java 2 23
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

789 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