I am loading some data from an XML document, modifying it, and writing back out to XML. The reading is done using a SAX parser library and the writing is done with a piece of custom code. Sometimes, the file is modified externally, and extra elements are added (such as references to stylesheets). Rather than losing these extra elements when I load and save the file, I would like to pass through any unknown tags so that they appear
When unknown elements are separate from interpreted elements, it should be straightforward to save unknown elements and attributes as strings and output these afterwards, but when they are interspersed and nested inside interpreted elements, it becomes less obvious.
Can anybody suggest a succinct way to do this? Would it be simpler to switch to a DOM parser? Performance is not an issue.
NB. I am working in C++ with the Gnome Glib::Markup::Parser, but would prefer language/library agnostic answers.