Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] feature request: being able to specify the NodeFactory for DomConverter

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <wolfgang.hoschek AT mac.com>
  • To: Elliotte Harold <elharo AT metalab.unc.edu>
  • Cc: xom-interest <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] feature request: being able to specify the NodeFactory for DomConverter
  • Date: Sat, 14 Jan 2006 08:45:08 -0800

I haven't tried it, but a quick scan over the code indicates that running this with a NodeFactory that returns null on startMakingElement() will cause a NPE (e.g. a XOMUtil.getNullNodeFactory()). In this case the element and its attributes and namespace declarations should be skipped, preserving the exact same semantics the Builder has.

Same holds for exceptions involving multiple root elements, missing root elements, etc. At least that's the guideline I've been using in all Nux build methods that take a NodeFactory.

Wolfgang.

On Jan 14, 2006, at 5:48 AM, Elliotte Harold wrote:

Steve Loughran wrote:
I'm trying to convert a w3c.dom.Document into a xom one, but need to
pass in my own node factory.

there isnt any option to pass one down, nor can I easily tack one in
by a bit of subclassing, as the DomConverter doesnt use a node factory
and doesnt have a method createNodeFactory() that I could have
overridden.


DOMConverter in CVS now contains a couple of methods that will allow you
to supply a NodeFactory when converting documents and document fragments
from DOM to XOM.

public static Document convert(org.w3c.dom.Document domDocument,
NodeFactory factory)
public static Nodes convert(org.w3c.dom.DocumentFragment fragment,
NodeFactory factory)

Please try this out and see if it works for you. Also, anyone else whose
using the DOMConverter may want test their code with this to see if I
accidentally broke it. The internal changes have been quite significant.

I'm also curious about thoughts on the API. One definite possibility is
making both methods return a Nodes object rather than a document. As is,
some of the trickier node factories can prevent the conversion by
returning the wrong thing in the wrong place. However simple cases
should work.

If this case had come up in the 1.0 time frame it might have convinced
me to make the convert methods instance methods instead of static
methods. However I'm hesitant to make that change now.

--
Elliotte Rusty Harold elharo AT metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ ref=nosim
_______________________________________________
XOM-interest mailing list
XOM-interest AT lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/xom-interest





Archive powered by MHonArc 2.6.24.

Top of Page