Solved

IBM XML4J Question

Posted on 2000-05-02
6
332 Views
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 (java.io.IOException e) {
            e.printStackTrace();
    }
  }
}

ERROR:
TESTXML.java:7: 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?
0
Comment
Question by:ubsjmg
[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 1

Accepted Solution

by:
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(".....");


   

0
 
LVL 1

Expert Comment

by:yanchou
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
0
 
LVL 1

Expert Comment

by:yanchou
ID: 2771543
Here is the example for xerces:


             
      import org.w3c.dom.Document;
      import org.apache.xerces.parsers.*;
           
        /**
         * cptest.java
         * 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!");
        }
      }
0
Independent Software Vendors: 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

by:ubsjmg
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.

CODE:
import com.ibm.xml.parser.*;
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:
testxml.java:1: Package com.ibm.xml.parser not found in import.
import com.ibm.xml.parser.*;
       ^
testxml.java:2: 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.
0
 

Expert Comment

by:scudder
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

0
 

Author Comment

by:ubsjmg
ID: 2865561
Answer accepted
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to install java on RHEL image on EC2 4 53
going to wrong jsp page 2 46
Java syntax, or is it Selenium 6 37
Java array 10 55
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 …
This video teaches viewers about errors in exception handling.

735 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