This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes clarification regarding Xerces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "clarification regarding Xerces" Watch "clarification regarding Xerces" New topic
Author

clarification regarding Xerces

Yell Srik
Ranch Hand

Joined: Mar 10, 2004
Posts: 61
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)
eammon bannon
Ranch Hand

Joined: Mar 16, 2004
Posts: 140
SAX: http://xml.apache.org/xerces2-j/sax.html
DOM: http://xml.apache.org/xerces2-j/dom.html
Have a look at the documentation.
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Also see the bunch of tutorials from here, it will sure start your engine..
http://www-106.ibm.com/developerworks/views/xml/tutorials.jsp


Spritle Software Blogs
Yell Srik
Ranch Hand

Joined: Mar 10, 2004
Posts: 61
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.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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).


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
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]

Yell
  • 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.
    Yell Srik
    Ranch Hand

    Joined: Mar 10, 2004
    Posts: 61
    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.
     
    wood burning stoves
     
    subject: clarification regarding Xerces