Re: [xml] how to not save <?xml version="1.0">
- From: "Martin (gzlist)" <gzlist googlemail com>
- To: veillard redhat com
- Cc: xml gnome org
- Subject: Re: [xml] how to not save <?xml version="1.0">
- Date: Tue, 26 Aug 2008 15:59:59 +0100
On 26/08/2008, Daniel Veillard <veillard redhat com> wrote:
On Mon, Aug 25, 2008 at 08:12:49PM +0100, Martin (gzlist) wrote:
> On 25/08/2008, Boz <boz boz org uk> wrote:
> > 2008/8/25 Steven é <huangxin52 hotmail com>:
> >
> > > I am a xml beginnner, and I am using libxml2 to edit some data for a system
> > > configuration file which doesn't contain <?xml version="1.0">(all elements
> > > in this xml are quite standard). Even Though adding this tag to the file has
> > > no effect on anything, I still don't like to add it.
> >
> >
> > As per http://xmlsoft.org/html/libxml-xmlsave.html#xmlSaveOption
> >
> > You can pass XML_SAVE_NO_DECL to prevent the xml declaration being output
>
> This is what I was going to say too, but also note you should only use
> unicode encodings (like the default, UTF-8) if you do this, as the
> encoding declaration goes in the XML prologue as well, and libxml2
> will happily omit it if instructed - even in cases where it's required
> for a well-formed document.
There are reasons for this:
- first the environment can provide an encoding so even if
you save to an non UTF-8 or non UTF-16 encoding, it is possible
to parse it back, assuming the environment (like an HTTP header
or filesystem metadata) provides it and it's given as an argument
to the parser (see appendix F)
- it's needed if you want to embbed a document fragment in another
because an XMLDecl found in the middle of a document is a
well-formedness error.
- it's also needed for XSLT, because <xsl:output> requires that
capability (not mandatory but everyone expects it)
Ah, sorry, yes there certainly are cases where this is exactly what
you want. (There are even times when you want even finer control over
serialisation details, like omitting the terminal newline.) Was just
pointing out a potential gotcha as the op was under the impression it
"has no effect on anything".
Martin
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]