appending data to xml file

E

Emmanuel

I am writing java application which will store data in XML file..Each
time when i execute that program ,previous data will be overidden..
Is it possible to append data to XML file,if anybody knows please
assist me
 
A

Andy Dingley

Emmanuel said:
Is it possible to append data to XML file,

No, at least not for most normal meanings of the term.

It's fundamental that an XML document has "closure". This is a good
feature, as it allows easy automatic detection of a truncated document.
It's achieved by enforcing the constraint that all XML documents have
one, and only one, root element. It's then obvious that the last
content in the XML file must be the end tag of this root element.

Unfortunately this also makes it impossible to continually append to an
XML file, at least by writing extra nodes to the end of it. You _could_
do it by opening the document and re-serialising it correctly, moving
the root's end tag onwards, but that's tricky too.

In general, the solution adopted is to not store well-formed XML in
these files, but rather to store a list of otherwise well-formed XML
elements (which may have structure within them, as usual). If you need
to parse the docuemnt as XML, just add the tags for the root element
before throwing the file's contents at the parser.
 
R

Richard Tobin

Andy Dingley said:
In general, the solution adopted is to not store well-formed XML in
these files, but rather to store a list of otherwise well-formed XML
elements (which may have structure within them, as usual). If you need
to parse the docuemnt as XML, just add the tags for the root element
before throwing the file's contents at the parser.

And you can "add the tags" by making the appended-to file be an
external entity referred to by a fixed top-level XML file:

<!DOCTYPE foo [
<!ENTITY data SYSTEM "data.xml">
]>
<foo>
&data;
</foo>

Then just append elements to data.xml.

-- Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top