Re: DOM3 Core clarification: isElementContentWhitespace?

Hi Alex.

Alex Vincent:
> I took a look at DOM 3 Core's isElementContentWhitespace definition,
> and I don't fully understand how it's supposed to work.  I thought at
> first glance it meant "Does this text node
> contain only whitespace?", but a fellow developer tells me it isn't that 
> simple.
> 
> Could I get some clarification on what it is supposed to mean?

DOM 3 Core refers to the [element whitepsace content] property in XML
Infoset, which says:

  A boolean indicating whether the character is white space appearing
  within element content (see [XML], 2.10 "White Space Handling"). Note
  that validating XML processors are required to provide this
  information. If there is no declaration for the containing element, or
  there are multiple declarations, this property has no value for white
  space characters. If no declaration has been read, but the [all
  declarations processed] property of the document information item is
  false (so there may be an unread declaration), then the value of this
  property is unknown for white space characters. It is always false for
  characters that are not white space.

So firstly Text.isElementContentWhitespace can only return true if the
processor is in validating mode, and all of the DTD/schema has been
read, and the text node does contain element content whitespace.  XML
1.0 Third Edition defines element content as:
  
  An element type has element content when elements of that type MUST
  contain only child elements (no character data), optionally separated
  by white space (characters matching the nonterminal S).

(I assume also that this definition also includes elements that cannot
have any child elements, too, but it’s maybe not clear just from that
sentence above.)

So basically if the text node contains only whitespace, and the
processor is validating, and according to the schema the parent element
of the text node has a content model that allows only elements, then the
method must return true.

-- 
Cameron McCormack, http://mcc.id.au/
 xmpp:heycam@jabber.org  ▪  ICQ 26955922  ▪  MSN cam@mcc.id.au

Received on Saturday, 8 July 2006 01:37:02 UTC