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

📄 ch01_05.htm

📁 Perl & XML. by Erik T. Ray and Jason McIntosh ISBN 0-596-00205-X First Edition, published April
💻 HTM
字号:
<html><head><title>Keep in Mind... (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="ch01_04.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="ch01_06.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr></table></div><h2 class="sect1">1.5. Keep in Mind...</h2><p>In many cases, you'll find that the XML modules onCPAN satisfy 90 percent of your needs. Of course, that final 10percent is the difference between being an essential member of yourcompany's staff and ending up slated for the nextround of layoffs. We're going to give you yourmoney's worth out of this book by showing you ingruesome detail how XML processing in Perl works at the lowest levels(relative to any other kind of specialized text munging you mayperform with Perl). To start, let's go over somebasic truths:</p><ul><li><p><b class="emphasis-bold">It doesn't matter where it comes from.</b></p><p>By the time the XML<a name="INDEX-29" />parsing part of aprogram gets its hands on a document, it doesn'tgive a camel's hump where the thing came from. Itcould have been received over a network, constructed from a database,or read from disk. To the parser, it's good (or bad)XML, and that's all it knows.</p><p>Mind you, the program as a whole might care a great deal. If we writea program that implements XML-RPC, for example, it better knowexactly how to use TCP to fetch and send all that XML data over theInternet! We can have it do that fetching and sending however welike, as long as the end product is the same: a clean XML documentfit to pass to the XML processor that lies at theprogram's core.</p><p>We will get into some detailed examples of larger programs later inthis book.</p></li><li><p><b class="emphasis-bold">Structurally, all XML <a name="INDEX-30" />documents are similar.</b></p><p>No matter why or how they were put together or to what purposethey'll be applied, all XML documents must followthe same basic rules of well-formedness: exactly one root element, nooverlapping elements, all attributes quoted, and so on. Every XMLprocessor's parser component will, at its core, needto do the same things as every other XML processor. This, in turn,means that all these processors can share a common base. PerlXML-processing programs usually observe this in their use of one ofthe many free parsing modules, rather than having to reimplementbasic XML parsing procedures every time.</p><p>Furthermore, the one-document, one-element nature of XML makesprocessing a pleasantly fractal experience, as any document invokedthrough an external entity by another document magically becomes"just another element" within theinvoker, and the same code that crawled the first document canskitter into the meat of any reference (and anything to which thereference might refer) without batting an eye.</p></li><li><p><b class="emphasis-bold">In meaning, all XML applications are different.</b></p><p>XML applications are the raison d'&ecirc;tre ofany one XML document, the higher-level set of rules they follow withan aim for applicability to some useful purpose -- be it fillingout a configuration file, preparing a network transmission, ordescribing a comic strip. XML applications exist to not only blesshumble documents with a higher sense of purpose, but to require thedocuments to be written according to a given applicationspecification.</p><p>DTDs help enforce the consistency of this structure. However, youdon't have to have a formal validation scheme tomake an application. You may want to create some validation rules,though, if you need to make sure that your successors (includingyourself, two weeks in the future) do not stray from the path you hadin mind when they make changes to the program. You should also createa validation scheme if you want to allow others to write programsthat generate the same flavor of XML.</p></li></ul><p>Most of the XML hacking you'll accomplish willcapitalize on this document/application duality. In most cases, yoursoftware will consist of parts that cover all three of these facts:</p><ul><li><p>It will accept input in an appropriate way -- listening to anetwork socket, for example, or reading a file from disk. Thisbehavior is very ordinary and Perlish: do whatever'snecessary here to get that data.</p></li><li><p>It will pass captured input to some kind of XML processor. Dollars todoughnuts says you'll use one of the parsers thatother people in the Perl community have already written and continueto maintain, such as <tt class="literal">XML::Simple</tt>, or the moresophisticated modules we'll discuss later.</p></li><li><p>Finally, it will Do Something with whatever that processor did to theXML. Maybe it will output more XML (or HTML), update a database, orsend mail to your mom. This is the defining point of your XMLapplication -- it takes the XML and does something meaningful withit. While we won't cover the infinite possibilitieshere, we will discuss the crucial ties between the XML processor andthe rest of your<a name="INDEX-31" /> program.</p></li></ul><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch01_04.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="ch01_06.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr><tr><td align="left" valign="top" width="228">1.4. A Myriad of Modules</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">1.6. XML Gotchas</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 + -