This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Hi, hope u don't mind answering this simple question from a newbie!! i have downloaded Xerces parser from the Apache web site and extracted all the required files in my machine in a folder named 'Xerces'. 1)i want to know how to parse my XML files using Xerces??? 2)when i write my DOM/SAX programs, how can i parse them using Xerces? thanks in advance. (by the way,i have j2sdk1.4.2 installed in my machine)
dear friends, i went throught the links u have mentioned, but i am afraid i need more clarifications from u: i have installed the xerces in a separate folder named "Xerces". now i have written a DOM program for my XML file. now should i save this program as say "XML1DOM.java", then go the command prompt and compile it as javac XML1DOM.java and run it as java XML1DOM? is the above procedure correct for parsing an XML file with xerces. if not, how should i proceed. i hope u don't mind answering such a basic level question. thanks in advance.
If "XML1DOM" is the name of the class that has a main() method then yes, that's how you execute it (assuming it's in the default package -- if it's not, then you need to specify the fully qualified name like "java com.foobar.XML1DOM"). In addition, you need to make sure that the Xerces .jar file is in the classpath (either via the CLASSPATH environment variable or via the "-classpath path/to/XercesImpl.jar" command-line argument).
Originally posted by Yell Srik: [QB] i have installed the xerces in a separate folder named "Xerces". now i have written a DOM program for my XML file. now should i save this program as say "XML1DOM.java", then go the command prompt and compile it as javac XML1DOM.java and run it as java XML1DOM? is the above procedure correct for parsing an XML file with xerces. if not, how should i proceed. [QB]
For brevity, lets create a new directory say(C:\XML)
Now copy the files XML1DOM.java and xerces.jar to this directory
xercer.jar can be found under the your Xerces folder, or copy the jar files which starts with xerces***.jar, the file size willbe more than 1.7mb
Now under the folder C:\xml, type javac -classpath "Xerces.jar" XML1DOM.java
The above step is to tell the java compiler to find the xerces related imports from the jar file xerces.jar
Now run java -cp "Xerces.jar" XML1DOM
Let me know if you are done up to this point.
The above step is one way which is specific to xerces parser, the latest jdk got its own xml parser, if you use generic imports for xml then your program can parse xml without the need of xerces. You can also gobally set the classpath for xerces and other related jars and complie/run the java-xml file without using the -classpath or -cp options.
Joined: Mar 10, 2004
hi balaji, i am sorry for the delay in replying. actually there has been some problem while installing JDK on my system. as soon as it is resolved, i will work on the procedure u suggested and then get to u.