2.4. SpacingYou'l l notice in examples throughout this book that we indent elements and add spaces wherever it helps make the code more readable to humans. Doing so is not unreasonable if you ever have to edit or inspect XML code personally. Sometimes, however, this indentation can result in space that you don't want in your final product. Since XML has a make-no-assumptions policy toward your data, it may seem that you're stuck with all that space. One solution is to make the XML processor smarter. Certain parsers can decide whether to pass space along to the processing application.[6] They can determine from the element declarations in the DTD when space is only there for readability and is not part of the content. Alternatively, you can instruct your processor to specialize in a particular markup language and train it to treat some elements differently with respect to space.
When neither option applies to your problem, XML provides a way to let a document tell the processor when space needs to be preserved. The reserved attribute xml:space can be used in any element to specify whether space should be kept as is or removed.[7]
For example: <address-label xml:space='preserve'>246 Marshmellow Ave. Slumberville, MA 02149</address-label> In this case, the characters used to break lines in the address are retained for all future processing. The other setting for xml:space is "default," which means that the XML processor has to decide what to do with extra space. Copyright © 2002 O'Reilly & Associates. All rights reserved. |
|