Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


changing the document element of a DOM

From: "Andy Fish" <ajfish@----------.--.-->
To: NULL
Date: 7/2/2004 5:02:00 PM
Hi,

I'm using XML DOM in Java and I have a function like this

    Element makeSomeXml(Document doc) {..}

This returns an Element owned by (but not appended to) the specified
document.

Now, when I call this function, sometimes I want to append the result
somewhere in the document, but sometimes I want to have the returned element
as a document in it's own right (i.e. as the root of the XML document). In
principle this seems like a reasonable requirement. I have an XML Element
and it's up to me whether I want to use it as the root element or plug it
into a bigger document.

The problem is that AFAIK a document must always have a root element, and
the root element cannot be replaced. nor can an existing element be
"upgraded" to be a document in it's own right. So I can't see a clean way of
doing what I want.

This seems a bit of a limitation in the way DOM represents the document
element - it seems to treat the root element and the document itself as the
same thing which isn't really the case. If I was editing XML in a file I
could leave all the namespace declarations and other stuff in place and
replace the root element.

Have I misunderstood the way the DOM works at the top level? Is there a
simple clean solution to what I want to do?

Many thanks in advance

Andy






transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent