XML technologies / XML / Perl & XML / Perl and XML / Keep in mind…
(Excerpt from “Perl & XML” by Erik T. Ray & Jason McIntosh)
You will often find that the XML modules from CPAN already meet 90 percent of your needs. The remaining 10 percent, however, distinguish indispensable employees from those who lose their jobs in the next stock-market slump. We will do our best to help you recover your investment in this book by showing XML processing in Perl in detail, down to its lowest level—low compared with the specialized text manipulation familiar in Perl. First, let us establish some basics:
Its origin does not matter. Once the program starts actually analyzing XML, we no longer care where the data came from: a network, database or disk. To the parser, it is just more or less proper XML; nothing else matters.
Of course this does not hold for the rest of the program or application. If, for example, we implemented XML-RPC, we would need to know how to send and receive Internet data using TCP. Whatever the solution, the end product must be the same: a clean XML document our processor expects.
Later in the book, more extensive examples explore this.
All XML documents have similar structures. Whatever their origin, construction or purpose, all XML documents must follow the syntactic rules of well-formedness: exactly one root element, all attribute values in single or double quotes, and so on. Every XML processor’s parser component essentially does the same things. They could therefore share a common core. In practice, they do, using freely available parser modules; only occasionally does someone analyze XML syntax by hand.
XML’s “one document, one element” philosophy can make processing almost fractal. A document read as an external entity, perhaps from an entirely different source, to insert into another simply becomes “another element.” The same code that just worked through the original now processes a different document without noticing.
XML applications nevertheless differ in meaning. XML applications justify every XML document’s existence. They add higher-level rules that make it useful for a particular purpose. Whether filling a configuration file, sending a document over a network or storing a comic-strip description, applications not only give XML greater meaning but impose requirements. This explains the countless XML-based specifications.
A DTD helps ensure structural consistency under these extra rules. An application need not have a formal validation schema, but defining rules is wise if future changes must stay on the intended path—especially your own changes two weeks later. This matters particularly when others will write programs using the same documents.
An XML programmer lives in the gray area of this application/document duality. Usually each of these facts has a corresponding part in your software:
An input document is read appropriately, perhaps from a socket in a network application or from a file elsewhere. This is normal in XML, and flexibility is natural to Perl programmers: do what you like, just give me the data.
The data goes to an XML processor. We would bet a doughnut that sooner or later you will use a parser the Perl community has already written and continues to develop. Whether it is
XML::Simpleor a more sophisticated module does not matter.Whatever the processor does, eventually it produces output: XML again, at least HTML, a database update or an email to your mother. That is the point of our application: XML should trigger something useful. We cannot begin to enumerate every possibility, but we can and will explore the important connection between the XML processor and the rest of the program.
Copyright © 2003 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “Perl & XML” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de
back to top