Re: Java and XML

Discussion in 'Java' started by Arne Vajhøj, Jul 12, 2008.

  1. Arne Vajhøj

    Arne Vajhøj Guest

    rhino wrote:
    > I'm getting very interested in XML, especially in using Java to create and
    > update XML files. However, the documents I'm reading about XML at IBM
    > Developer Works are, for the most part, quite dated with dates in 2002 and
    > earlier being typical.


    The JAXP interface has not changed much since then. It is fine.

    Since then StAX and JAXB has been added, but you probably want plain
    JAXP.

    > How do I find out what the current practices are on XML and how to work with
    > it in Java? I don't want to waste a lot of time trying to figure out how to
    > use tools and techniques that have long since been replaced by far better
    > techniques. For example, having to use DOM to read an entire XML document in
    > order to insert a single element seems like a pretty dubious way of doing
    > something. It reminds me of storing data on magnetic tape and having to read
    > through most of the tape to add information to it. This seems more like the
    > 1960s than the first decade of the 21st century. I have to assume that
    > someone has come up with better approaches by now.


    Reading the entire document into memory is by far the easiest.

    A W3C document and then pick data with XPath is a piece of cake. And
    absolutely the modern way of doing it.

    If your XML files are too big for the approach, then you can look
    at SAX. SAX is as old as W3C DOM in Java - and I really think it
    is a better fit for your tape analogy than W3C DOM !

    Arne
    Arne Vajhøj, Jul 12, 2008
    #1
    1. Advertising

  2. Lew wrote:
    > Arne Vajhøj wrote:
    >> If your XML files are too big for the approach, then you can look
    >> at SAX. SAX is as old as W3C DOM in Java - and I really think it
    >> is a better fit for your tape analogy than W3C DOM !

    >
    > SAX, and its new cousin StAX, can be blazingly fast and memory efficient
    > for XML processing. They support and promote a strategy of single-pass
    > processing, where DOM approaches tend to be memory intensive with a
    > multi-pass sensibility. Where the streaming parser approach applies, it
    > can really perform very well.


    Yes - they perform well.

    But they do have the same sequential processing characteristics
    as tapes unlike DOM and XPath which is more like random access on
    disk files.

    Arne
    Arne Vajhøj, Jul 13, 2008
    #2
    1. Advertising

  3. Lew wrote:
    > Even when one needs random access, one might still use a streaming
    > approach to load the InputSource. java.util.Properties is an example -
    > <http://java.sun.com/javase/6/docs/api/java/util/Properties.html>
    > it could (and likely does) use a streaming parser to implement
    > loadFromXML(), then it provides random access for its clients from an
    > in-memory structure that is not a DOM tree.


    A quick glance in the source code seems to indicate that it uses
    W3C DOM.

    And considering that properties files usually are KB not MB, then
    it is should be OK.

    Arne
    Arne Vajhøj, Jul 13, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page