Schemas

The W3C XML Schema Language uses the whiteSpace facet to specify whether white space in an attribute or element with a simple type should be preserved, replaced , or collapsed .

  • Preserved white space is like xml:space="preserve" ; that is, all white space is considered to be significant.

  • Replaced white space replaces all tabs, carriage returns, and line feeds with a single space each. Thus the number of white space characters is preserved but their type may be changed.

  • Collapsed white space first replaces all carriage returns and line feeds with a single space each, then replaces each run of consecutive spaces with a single space, and finally trims all leading and trailing white space.

However, once again this only offers a hint to the client application. The parser will still report all white space to the client application in the same way it would without the schema. Indeed, the whiteSpace facet doesn't even change the set of valid content for an element. For example, suppose the shape element is declared in a schema like the one below.

 <xsd:element name="shape">   <xsd:simpleType>     <xsd:restriction base="xsd:string">       <xsd:whiteSpace value="collapse"/>     </xsd:restriction> </xsd:element> 

The following three elements are all still valid.

 <shape> triangle    rectangle  square  </shape> <shape>triangle rectangle square</shape> <shape>       triangle       rectangle       square </shape> 

Bottom line: White space is significant in XML documents except in the prolog, epilog, and tags. Parsers report all white space in element content and attribute values to the client application. Depending on the DTD, the xml:space attribute, and the value of the whiteSpace facet in the schema, parsers may indicate that white space is or is not significant. However, it will all be reported . It is up to each individual application to determine the rules by which white space is treated.



Effective XML. 50 Specific Ways to Improve Your XML
Effective XML: 50 Specific Ways to Improve Your XML
ISBN: 0321150406
EAN: 2147483647
Year: 2002
Pages: 144

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net