appending data to xml file

Discussion in 'XML' started by Emmanuel, Oct 13, 2006.

  1. Emmanuel

    Emmanuel Guest

    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
    Emmanuel, Oct 13, 2006
    #1
    1. Advertising

  2. Emmanuel

    Andy Dingley Guest

    Emmanuel wrote:

    > 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.
    Andy Dingley, Oct 13, 2006
    #2
    1. Advertising

  3. In article <>,
    Andy Dingley <> wrote:

    >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
    Richard Tobin, Oct 13, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Red Ogden
    Replies:
    0
    Views:
    1,089
    Red Ogden
    Jul 16, 2003
  2. Thomas Heller

    appending data to an xml file

    Thomas Heller, Jan 11, 2005, in forum: Python
    Replies:
    1
    Views:
    342
    Peter Hansen
    Jan 12, 2005
  3. Emmanuel

    Appending Data to XML File

    Emmanuel, Oct 13, 2006, in forum: Java
    Replies:
    3
    Views:
    321
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Oct 15, 2006
  4. Frank
    Replies:
    1
    Views:
    349
    sloan
    Mar 6, 2007
  5. Replies:
    8
    Views:
    449
Loading...

Share This Page