XML Processing with Perl, Python, and PHP (2002).pdf

时间:2022-09-08 05:46:46
【文件属性】:
文件名称:XML Processing with Perl, Python, and PHP (2002).pdf
文件大小:2.12MB
文件格式:PDF
更新时间:2022-09-08 05:46:46
XML Processing  Perl Python PHP  Introduction A lmost ten years ago, my introduction to the commercial world was handling and dealing with the databases of a UK government body. We used a free text-retrieval system to store information about software products, teachers, and trainers. Although we had fields for the information, when we entered a search, we were searching the whole document, not just one field or a collection of them. One of my jobs was to write programs that processed the information, deduced the fields, extracted compound addresses and telephone numbers, and tidied up the results to put into a new version of the database. Access to the database was through a Sun-based Unix system, and the PCs and Macs on the network didn’t talk to each other, but they did talk over Telnet to the Sun database server. You could do searches, edit information, and cut and paste, but you had no control over how the information looked without manually massaging the text you’d just copied. Ten Years Later Ten years later, for the most part I still do the same thing, although not with the same com- pany or the same information. Ultimately, though, I’m still working with databases and stor- age systems that rely on managing and dealing with a lot of text, but in a structured way that is somehow intelligent enough to know what I’m storing but flexible enough not to restrict what it is I want to store. The information I’m dealing with has to be accessible on a number of different platforms. In my home office alone, I’ve got Macs, Unix, Linux, at least five different versions of Win- dows, and handhelds running EPOC32 and PalmOS. They support different character sets, and I have to be able to convert the information into more usable formats, such as HTML for display, or stored in more rigid systems, like an RDBMS. What should I use? Do I play with a free text-retrieval system again? If I use a database system, how will I transfer my contacts from my desktop Mac to my portable Windows notebook or to Palm? If I want to view the information online, can I con- vert it easily? If I build an application that provides me with access to the information, how do I go about storing my preferences? How do I make the information available over the net- work in a format that can be accessed by all the machines that need to use it? 4021fm.qxd 11/2/01 4:27 PM Page xxi xxii The Solution The solution, if you haven’t guessed it already, is that I should use XML, the Extensible Markup Language. I get all the flexibility I need without losing any capabilities. I can add new fields, structures, and layouts to the information without breaking any of the existing tools. I can use fairly standard applications to convert the XML information into a more suit- able format. In fact, I can easily convert an XML document into a structured database, and I can query the database using SQL and export the records back in XML format. Alternatively, I can store everything in XML and access, process, and update the infor- mation directly. If I want, I can even query the XML document using XQL. I can use it to exchange information between platforms and, because all the information is in a standard and easily processed format, I should be able to use the information on any platform I have access to. The Tools I’m not actually a firm believer in being to able to specify the “right” tool for the job. Each programming job is different and may well have a number of different solutions and possible tools that would ease the process. However, I do know that scripting languages offer one of the fastest development environments, and many offer a wider range of supported platforms (and more accessible methods) than more traditional XML processing tools based on Java or C/C++. Python, for example, runs on MacOS, Unix, Windows and PalmOS. Rebol runs on even more. AppleScript is a standard part of every MacOS revision since 8.0 and is even included in MacOS X. Perl is supplied as standard with most Linux revisions, and even some commer- cial Unix installations include Perl as a standard option. In fact, I have access to a wider range and more easily accessible set of development tools off the shelf than any Java or C/C++ development environment I know of. Furthermore, some of them are so easy to use that it’s hard to understand why you would even look at another language. Did you know, for example, that you can talk to any application in MacOS with AppleScript? Think about what you could do if only you knew how to tell Perl to convert your XML- based documents into Word documents for editing, or to HTML for viewing on the Web, or to SQL tables for storage in a database! Introduction 4021fm.qxd 11/2/01 4:27 PM Page xxii xxiii This Book If you haven’t already guessed, this book is all about parsing, processing, and working with XML using a variety of scripting languages. After a brief XML refresher, I address the lan- guages in turn to show how each provides solutions for getting at the power of XML. Along the way, I address some of the important protocols, such as SOAP and XML-RPC, that make seamless data transfer possible. Throughout this book you’ll find sample scripts. You can download the complete versions of the scripts by going to www.sybex.comand following the link to the page for this book. XML seems to be everywhere today and used in a myriad of ways, especially in the vital and growing world of e-commerce. This book is designed to help you make the most of it. I hope that you will return to these pages often as you discover more uses for XML

网友评论