[jdom-interest] Parsing a File using DOMBuilder?

Kevin Jones kevinj at develop.com
Wed Jun 12 11:34:45 PDT 2002


The argument goes 'Why build a DOM to build a JDOM?' If you have a DOM
already parsing it into a JDOM is fine, but if all you have is a raw
infoset there's no point in going XML->DOM->JDOM. Why not just build the
JDOM using the SAX parser as input?

In fact, these two lines are what you want

>    SAXBuilder   sax     = new SAXBuilder();
>    Document     saxDoc  = sax.build(new File(myXMLFile));

give you what you want - an org.jdom.Document

or even

    SAXBuilder   sax     = new SAXBuilder();
    Document     saxDoc  = sax.build(myXMLFile);

Kevin Jones
Developmentor
www.develop.com


> -----Original Message-----
> From: jdom-interest-admin at jdom.org 
> [mailto:jdom-interest-admin at jdom.org] On Behalf Of Robert J. 
> Sanford, Jr.
> Sent: 12 June 2002 02:42
> To: jdom-interest at jdom.org
> Subject: [jdom-interest] Parsing a File using DOMBuilder?
> 
> 
> This is my first experience with JDOM so bear with me. I 
> tried searching the interest email archives for "DOM 
> deprecate" but all of the hits were for DOM and that was a 
> bit much. Anyway...
> 
> I just downloaded B8 and started to compile the sample apps 
> and got a deprecation warning when instantiating a new 
> DOMBuilder with a File object. So I started looking through 
> the javadocs and from reading the DOMBuilder javadoc I get 
> the impression that I'm supposed to already have instantiated 
> an org.w3c.dom.Document to use the DOMBuilder. From looking 
> through the rest of the javadoc I get the impression that in 
> order to instantiate a DOMBuilder from an XMLFile I need to 
> use something like:
>    SAXBuilder   sax     = new SAXBuilder();
>    Document     saxDoc  = sax.build(new File(myXMLFile));
>    DOMOutputter out     = new DOMOutputter();
>    DOMBuilder   dom     = new DOMBuilder();
>    Document     domDoc  = dom.build(out.output(saxDoc));
> 
> Is this right? Is there a shorter way to do this? I was 
> thinking from reading the DOMBuilder sample that:
>    DOMBuilder   dom     = new DOMBuilder();
>    Document     domDoc  = dom.build(new File(myXMLFile));
> 
> was looking to be significantly simpler...
> 
> rjsjr
> 
> _______________________________________________
> To control your jdom-interest membership: 
> http://lists.denveronline.net/mailman/options/jdom-interest/yo
uraddr at yourhost.com




More information about the jdom-interest mailing list