📄 ch04_03.htm
字号:
<html><head><title>The Parser as Commodity (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 & 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 & 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_02.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_04.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr></table></div><h2 class="sect1">4.3. The Parser as Commodity</h2><p>You<a name="INDEX-333" /> don't have to writean XML processing program that separates parser from handler, butdoing so can be advantageous. By making your program modular, youmake it easier to organize and test your code. The ideal way tomodularize is with objects, communicating on sanctioned channels andotherwise leaving one another alone. Modularization makes swappingone part for another easier, which is very important in XMLprocessing.</p><p>The XML stream, as we said before, is an abstraction, which makes thesource of data irrelevant. It's like the spigot youhave in the backyard, to which you can hook up a hose and water yourlawn. It doesn't matter where you plug it in, youjust want the water. There's nothing special aboutthe hose either. As long as it doesn't leak and itreaches where you want to go, you don't care ifit's made of rubber or bark. Similarly, XML parsershave become a commodity: something you can download, plug in, and seeit work as expected. Plugging it in easily, however, is the trickypart.</p><p>The key is the screwhead on the end of the spigot.It's a standard gauge of pipe that uses a specificthread size, and any hose you buy should fit. With XML event streams,we also need a standard interface there. XML developers have settledon SAX, which has been in use for a few years now. Until recently,Perl XML parsers were not interchangeable. Each had its owninterface, making it difficult to swap out one in favor of another.That's changing now, as developers adopt SAX andagree on conventions for hooking up handlers to parsers.We'll see some of the fruits of this effort in <a href="ch05_01.htm">Chapter 5, "SAX"</a>. </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_02.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_04.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr><tr><td align="left" valign="top" width="228">4.2. Events and Handlers</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.4. Stream Applications</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 © 2002</a> O'Reilly & 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 + -