ptg7068951
Reading an XML File 303
A vital skill to develop in your Java programming is to learn where to look
for Java classes and packages you can employ in your own projects.
Reusing a well-developed class library is considerably easier than coding
your own classes from scratch.
The Java team at Oracle isn’t the only developer producing terrific Java
classes, which you see during the remainder of this hour by using XOM, a
class library developed by the computer programmer and book author
Elliotte Rusty Harold. Harold, an expert in both the Java language and
XML, grew frustrated with how existing XMLlibraries worked. (You might
be sensing a theme here—Java itself was developed by James Gosling as an
expression of his frustration with another language.)
Harold created his own class library that represents XMLdata as a tree
holding each element as a node.
You can download thelibrary from http://www.xom.nu.
Unpack the archive in a folder on your system. I used C:\java\XOMon
my Windows XPsystem, devoting the top-level folder C:\javato Java
libraries I use. After downloading and unpacking a library, you must add
it to your current project in NetBeans:
- Choose File, Project Properties. The Project Properties dialog opens.
- Click Libraries in the Categories pane, and then click the Add
Library button. The Add Library dialog opens. - Click the Create button. The Create New Library dialog opens.
- Enter XOMin the Library Name field and click OK. The Customize
Library dialog opens. - Click Add JAR/Folder. The Browser JAR/Folder dialog opens.
- Find the folder where you saved XOM and choose the xom-1.2.1
and xom-samplesfiles. (The version number of XOM might be differ-
ent.) Click Add JAR/Folder. - In the Customize Library dialog, click OK.
- In the Add Library dialog, choose XOM and click Add Library.
- In the Project Properties dialog, click OK.
The XOM library is now available to yourproject.
XOM has classes to read and write XMLdata, saving it to files and other
destinations.
CAUTION
XOM has been made available
at no cost under an open
source license,the GNU Lesser
General Public License (LGPL).
Yo u c a n d i s t r i b u t e t h e X O M
library without modification with
Java applications that rely on it.
Yo u a l s o c a n m a ke c h a n g e s t o
the classes in the library,but
you must make these changes
available under the LGPL. You
can view the full details of the
license at http://www.xom.nu/
license.xhtml.