Link to home
Start Free TrialLog in
Avatar of ubsjmg
ubsjmg

asked on

IBM XML4J Question

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?
ASKER CERTIFIED SOLUTION
Avatar of yanchou
yanchou

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yanchou
yanchou

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
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!");
        }
      }
Avatar of ubsjmg

ASKER

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

Avatar of ubsjmg

ASKER

Answer accepted