No, I don't really have any reservations about JDOM...except for the fact that there has been little to zero development on it of late. Check out the amount of time that has passed since the last beta release (9 - 10 months!). At this rate, they'll release a 1.0 version in a couple more years while Xerces development steams on ahead. JDOM may be elegant, but I wish the main developers would put their nose to the grindstone and get, at least, another beta release out in short order!

To tell you the truth, I would just use a SAX parser. That will be faster than any of the other methods including JDOM.

Jake

At 12:01 PM 1/4/2003 -0600, you wrote:
Howdy,

Thanks for all the good suggestions. I'm going with JDOM, just because
it's pretty darn elegant and simple. It also appears that it will be
(if not already) an XML standard for Java.  So all signs indicate that
I'm not marrying myself to an obscure API.

Do any of you have reservations about JDOM?

Thanks,
-FB

On Saturday, January 4, 2003, at 08:02  AM, Jacob Kjome wrote:

Well,

There are a number of parsers available.  You can use DOM, JDOM,
DOM4J, SAX, or, actually, you might want to try out XPath using Jaxen.

Here is an example of reading in a document using DOM....and no
specific external package so you don't marry yourself to a particular
implementation...

DocumentBuilderFactory dbfactory =
DocumentBuilderFactory.newInstance();
dbfactory.setNamespaceAware(true);
Document doc = null;
try {
    DocumentBuilder dbuilder = dbfactory.newDocumentBuilder();
    InputStream = context.getResourceAsStream("/WEB-INF/mydoc.xml");
    doc = dbuilder.parse(is);
}
catch (ParserConfigurationException pce) {}
catch (SAXException se) {}
catch (IOException ioe) {}


You can then grab a NodeList of some part of the document and iterate
through that or you can then use Jaxen to get to specific data with
XPath queries....


try {
    XPath xpath = new
DOMXPath("//MyElement[@myAttribute='someSpecificValue']/ AnotherElement");
    Node node = (Node)xpath.selectSingleNode(domainDoc);
    //now do something with the node
}
catch (XPathSyntaxException xse) {}
catch (JaxenException je) {}


If you know, in advance, all the elements you will need to read, then
you might want to write a SAX parser for your document.  It will be
the fastest method....or you could use XML data binding using Zeus or
JAXB which will allow you to read in a whole document and access all
the data using standard Java Bean getters and set the values using
standard Java bean setters.  In this case, you don't even need to
worry about XML since the fact that it is XML is totally hidden from
you.  You can then marshal your updated object (assuming you modified
it) back to an XML document.

There are lots of ways to do this.  Which way you choose depends on
your needs and what API's you feel most comfortable with.

Jake


At 07:29 PM 1/3/2003 -0600, you wrote:
I have a servlet and I want it to read it's data from an XML file.
There's more than one way of doing this task and I'm fishing for best
practices.
Can anyone provide me with some links to example code? I'm sure this
has been beaten to death and I don't want to reinvent the wheel.

Thanks!


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to