A
Andy Fish
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
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