http://qs321.pair.com?node_id=60849


in reply to Weirdness (and bugfix for) XML::DOM ...

The specifications for XML 1.0 are set forth by the World Wide Web Consortium here. These specs state:
Enumerated Attribute Types ... [59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ' +)' [VC: Enumeration] ... Examples of attribute-list declarations: ... <!ATTLIST list type (bullets|ordered|glossary) "ordered"> ...
My reading of the XML specifications is that pipes in attribute-list declarations should not have spaces surrounding them.

Similarly, in XML 1.0 one ought not to surround pipes with spaces in element type declarations either:

Examples of element type declarations: ... <!ELEMENT p (#PCDATA|emph)* >

It is unfortunate that attr test contains what may be a malformed XML Document Type Declaration. However, the XML specifications contain no requirements for user-friendly error handling. All an XML parser has to do when encountering bad XML is stop. It need do no more.

Update: Our resident XML guru Mirod has pointed out to me that the S? in the XML rule I quoted means that the pipe can, indeed be surrounded by whitespace. He opines that there is an error, but that it is likely in XML::Parser on which XML::DOM is built.

Mirod points out that according to Rule 3

(see rule 3: S ::= (#x20 | #x9 | #xD | #xA)+ >

Hence, S? means there can be an optional space around the '|'

Moral. I should learn to read XML specs better. Thanks to mirod for correcting this error.

Replies are listed 'Best First'.
Re: Re: Weirdness (and bugfix for) XML::DOM ...
by mirod (Canon) on Feb 26, 2001 at 16:23 UTC

    Nope!

    In Rule 59 the S? is defined by:

    White Space [3] S ::= (#x20 | #x9 | #xD | #xA)+

    So (  toto  |  tata  ) is just as valid as (  toto  | tata  ). The problem is that expat and XML::Parser report _everything_ in the document, including non-significant spaces. Now Expat is required by the spec to do so. XML::Parser could probably choose to normalize those whitespaces but does not, and XML::DOM definitely should normalize them but does not. The SAX-2 extension for declaration for example normalizes declarations by removing all spaces around tokens.

    The bottom-line is that this is a feature of XML::DOM that could easily pass for a bug (and should be fixed as soon as somebody provides a patch, I certainly don't want to get involved in XML::DOM but line 1970 of the DOM.pm in libxml-enno-1.04pre3 seems like the place to insert the normalization for attribute declarations, then on to element content models before line 2343).

    As a side note, the best way to read the XML specification is probably to go to The Annotated XML Specification for the spec and Tim Bray's comments on xml.com

    Update: Crap! My mistake (as usual :--(, XML::DOM (or maybe XML::Parser) does normalize attribute declarations. Actually that's why the test fails. It is fixed in libxml-enno-1.04pre though. The only remaining problem is that 1.04 does not pass the test on 5.6.0