Re: [xml] Whitespace handling with schema

On Thu, Feb 24, 2011 at 12:53:25PM +0100, Mark Van Peteghem wrote:

I have an XML document with a schema defined in it. I try to make
libxml2 apply whitespace normalization as specified in the schema,
but it doesn't seem to work. Here is an example:


The whitespace is preserved when I call
xmlTextReaderConstValue(...), even though <xsd:whiteSpace
value='collapse'/> is specified.

Do I need to do something more to make this work, or can my
application ask whether the string can be collapsed?

PS: I did add a schema valid context created with a null pointer,
like I read somewhere:
       xmlSchemaValidCtxtPtr validator = xmlSchemaNewValidCtxt(0);
       xmlSchemaSetValidErrors(validator, SchemaValidityErrorFunc,
SchemaValidityErrorFunc, reader);
       int rv = xmlTextReaderSchemaValidateCtxt(reader, validator, 0);
and rv is 0.

  In a nutshell, the behaiour of XML-1.0 parser was defined in 1997
when the spec was produced. It tells rather precisely what must be
provided to applications and while DTD were included and could influence
the output, this behaviour is fixed and somehow cast in stone, embedded
with parsers everytwhere.
  Schemas, be them XSD or RNG are just a validation layer sitting on top
they do not influence the parsing itself. I don't think you can expect
from an XML conformant parser to change it's behaviour based on a spec
that it doesn't reference.

  <xsd:whiteSpace value='collapse'/>
certainly has a meaning, but at the application layer, not at the parser


Daniel Veillard      | libxml Gnome XML XSLT toolkit
daniel veillard com  | Rpmfind RPM search engine | virtualization library

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]