⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch02_04.htm

📁 Perl & XML. by Erik T. Ray and Jason McIntosh ISBN 0-596-00205-X First Edition, published April
💻 HTM
字号:
<html><head><title>Spacing (Perl and XML)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Erik T. Ray and Jason McIntosh" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly &amp; Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="059600205XL" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="Perl and XML" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img alt="Book Home" border="0" src="gifs/smbanner.gif" usemap="#banner-map" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Perl &amp; XML" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch02_03.htm"><img alt="Previous" border="0" src="../gifs/txtpreva.gif" /></a></td><td align="center" valign="top" width="228" /><td align="right" valign="top" width="228"><a href="ch02_05.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr></table></div><h2 class="sect1">2.4. Spacing</h2><p>You'l<a name="INDEX-92" /> <a name="INDEX-93" />lnotice in examples throughout this book that we indent elements andadd spaces wherever it helps make the code more readable to humans.Doing so is not unreasonable if you ever have to edit or inspect XMLcode personally. Sometimes, however, this indentation can result inspace that you don't want in your final product.Since XML has a make-no-assumptions policy toward your data, it mayseem that you're stuck with all that space.</p><p>One solution is to make the XML processor smarter. Certain parserscan decide whether to pass space along to the processingapplication.<a href="#FOOTNOTE-6">[6]</a> They can determinefrom the element declarations in the DTD when space is only there forreadability and is not part of the content. Alternatively, you caninstruct your processor to specialize in a particular markup languageand train it to treat some elements differently with respect tospace.</p><blockquote class="footnote"> <a name="FOOTNOTE-6" /><p>[6]A parser is a specialized XML handlerthat preprocesses a document for the rest of the program. Differentparsers have varying levels of"intelligence" when interpretingXML. We'll describe this topic in greater detail in<a href="ch03_01.htm">Chapter 3, "XML Basics: Reading and Writing"</a>. </p> </blockquote><p>When neither option applies to your problem, XML provides a way tolet a document tell the processor when space needs to be preserved.The reserved attribute <tt class="literal">xml:space</tt> can be used inany element to specify whether space should be kept as is orremoved.<a href="#FOOTNOTE-7">[7]</a> </p><blockquote class="footnote"> <a name="FOOTNOTE-7" /><p>[7]We know that it's reservedbecause it has the special "xml"prefix. The XML standard defines special uses and meanings forelements and attributes with this prefix.</p> </blockquote><p>For example:</p><blockquote><pre class="code">&lt;address-label xml:space='preserve'&gt;246 Marshmellow Ave.Slumberville, MA02149&lt;/address-label&gt;</pre></blockquote><p>In this case, the characters used to break lines in the address areretained for all future processing. The other setting for<tt class="literal">xml:space</tt> is"default," which means that the XMLprocessor has to decide what to do with extra space.</p><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch02_03.htm"><img alt="Previous" border="0" src="../gifs/txtpreva.gif" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"><img alt="Home" border="0" src="../gifs/txthome.gif" /></a></td><td align="right" valign="top" width="228"><a href="ch02_05.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr><tr><td align="left" valign="top" width="228">2.3. Namespaces</td><td align="center" valign="top" width="228"><a href="index/index.htm"><img alt="Book Index" border="0" src="../gifs/index.gif" /></a></td><td align="right" valign="top" width="228">2.5. Entities</td></tr></table></div><hr width="684" align="left" /><img alt="Library Navigation Links" border="0" src="../gifs/navbar.gif" usemap="#library-map" /><p><p><font size="-1"><a href="copyrght.htm">Copyright &copy; 2002</a> O'Reilly &amp; Associates. All rights reserved.</font></p><map name="library-map"><area shape="rect" coords="1,0,85,94" href="../index.htm"><area shape="rect" coords="86,1,178,103" href="../lwp/index.htm"><area shape="rect" coords="180,0,265,103" href="../lperl/index.htm"><area shape="rect" coords="267,0,353,105" href="../perlnut/index.htm"><area shape="rect" coords="354,1,446,115" href="../prog/index.htm"><area shape="rect" coords="448,0,526,132" href="../tk/index.htm"><area shape="rect" coords="528,1,615,119" href="../cookbook/index.htm"><area shape="rect" coords="617,0,690,135" href="../pxml/index.htm"></map></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -