Felix Engelhardt wrote:
No, DOM documents are required to have exactly one root node, not several.
Because a well-formed XML document is required to have exactly one
top-level element, not several. The file you've shown us is not an XML
document, though it may be an XML External Entity.
DOM DocumentFragments can have several top-level elements. But I don't
know of an off-the-shelf parser that will read an External Entity
directly into a DocumentFragment.
One solution is to set up a bit of additional code which wraps a
top-level element around the data as it's read in -- for example, set up
a SAXFilter which generates an extra startElement after the
startDocument event and an extra endElement before the endDocument
event. That does require that the rest of your code be aware this dummy
element was introduced, but that's usually straightforward... or you can
move these trees into a DocumentFragment, if you're working with DOMs.
Saving the data back out may be complicated since, like parsers,
serializers may or may not assume they're intended to process
well-formed XML document. Generally, though, they're more forgiving and
you can get away with using the standard serializer; it's just your
responsibility not to write out the dummy wrapper element.
Good luck.
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden