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

📄 ch04_04.htm

📁 Perl & XML. by Erik T. Ray and Jason McIntosh ISBN 0-596-00205-X First Edition, published April
💻 HTM
字号:
<html><head><title>Stream Applications (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="ch04_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="ch04_05.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr></table></div><h2 class="sect1">4.4. Stream Applications</h2><p>Stream<a name="INDEX-334" /><a name="INDEX-335" />processing is great for many XML tasks. Here are a few of them:</p><dl><dt><i>Filter</i></dt><dd><p>A <em class="emphasis">filter</em><a name="INDEX-336" /> outputs an almost identical copy ofthe source document, with a few small changes. Every incidence of an<tt class="literal">&lt;A&gt;</tt> element might be converted into a<tt class="literal">&lt;B&gt;</tt> element, for example. The handler issimple, as it has to output only what it receives, except to make asubtle change when it detects a specific event.</p></dd><dt><i>Selector</i></dt><dd><p>If you want a specific piece of information from a document, withoutthe rest of the content, you can write a<em class="emphasis">selector</em><a name="INDEX-337" /> program. This programcombs through events, looking for an element or attribute containinga particular bit of unique data called a <em class="emphasis">key,</em>and then stops. The final job of the program is to output thesought-after record, possibly reformatted.</p></dd><dt><i>Summarizer</i></dt><dd><p>This<a name="INDEX-338" /> program type consumes a document andspits out a short summary. For example, an accounting program mightcalculate a final balance from many transaction records; a programmight generate a table of contents by outputting the titles ofsections; an index generator might create a list of links to certainkeywords highlighted in the text. The handler for this kind ofprogram has to remember portions of the document to repackage itafter the parser is finished reading the file.</p></dd><dt><i>Converter</i></dt><dd><p>This sophisticated type of <a name="INDEX-339" />program turns yourXML-formatted document into another format -- possibly anotherapplication of XML. For example, turning<a name="INDEX-340" />DocBook XML into HTML can be done in thisway. This kind of processing pushes stream processing to its limits.</p></dd></dl><p>XML stream processing works well for a wide variety of tasks, but itdoes have limitations. The biggest problem is that everything isdriven by the parser, and the parser has a mind of its own. Yourprogram has to take what it gets in the order given. Itcan't say, "Hold on, I need to lookat the token you gave me ten steps back" or"Could you give me a sneak peek at a token twentysteps down the line?" You can look back to theparsing past by giving your program a memory. Clever use of datastructures can be used to remember recent events. However, if youneed to look behind a lot, or look ahead even a little, you probablyneed to switch to a different strategy: tree processing, the topic of<a href="ch06_01.htm">Chapter 6, "Tree Processing"</a>.</p><p>Now you have the grounding for XML stream processing.Let's move on to specific examples and see how towrangle with XML streams in real life.</p><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch04_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="ch04_05.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr><tr><td align="left" valign="top" width="228">4.3. The Parser as Commodity</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">4.5. XML::PYX</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 + -