Python and XML: Includes index
معرفی کتاب «Python and XML: Includes index» نوشتهٔ Jones, Christopher A;Jr, Fred L Drake، منتشرشده توسط نشر O'Reilly Media در سال 2001. این کتاب در 2 صفحه، فرمت pdf، زبان انگلیسی ارائه شده است. «Python and XML: Includes index» در دستهٔ بدون دستهبندی قرار دارد.
If you are a Python programmer who wants to incorporate XML into your skill set, this is the book for you. Python has attracted a wide variety of developers, who use it either as glue to connect critical programming tasks together, or as a complete cross-platform application development language. Yet, because it is object-oriented and has powerful text manipulation abilities, Python is an ideal language for manipulating XML. Python & XML gives you a solid foundation for using these two languages together. Loaded with practical examples, this new volume highlights common application tasks, so that you can learn by doing. The book starts with the basics then quickly progresses to complex topics, like transforming XML with XSLT, querying XML with XPath, and working with XML dialects and validation. It also explores the more advanced issues: using Python with SOAP and distributed web services, and using Python to create scalable streams between distributed applications (like databases and web servers). The book provides effective practical applications, while referencing many of the tools involved in XML processing and Python, and highlights cross-platform issues along with tasks relevant to enterprise computing. You will find ample coverage of XML flow analysis and details on ways in which you can transport XML through your network. Whether you are using Python as an application language, or as an administrative or middleware scripting language, you are sure to benefit from this book. If you want to use Python to manipulate XML, this is your guide. Preface......Page 3 Audience......Page 4 Organization......Page 5 How to Contact Us......Page 7 Acknowledgments......Page 8 Chapter 1. Python and XML......Page 9 1.1.1 Application Neutrality......Page 10 1.1.2 Hierarchical Structure......Page 12 1.1.4 International Language Support......Page 13 1.2.1 XML 1.0 Recommendation......Page 15 1.2.3 XML as a Foundation......Page 16 1.3 The Power of Python and XML......Page 17 1.3.2 The SAX and DOM APIs......Page 20 Example 1-1. bookhandler.py......Page 21 Example 1-2. dombook.py......Page 23 1.4 What Can We Do with It?......Page 24 2.1 XML Structure in a Nutshell......Page 25 2.2.1 Document Type Definitions......Page 26 2.2.2.1 XML Schema......Page 27 2.3 Types of Conformance......Page 28 2.4 Physical Structures......Page 30 2.5.1 Characters in XML Documents......Page 31 2.5.2 Text, Character Data, and Markup......Page 32 2.5.3 Whitespace in Character Data......Page 34 2.5.5 Language Identification......Page 36 2.5.6 The Document Prolog......Page 37 2.5.7 Start, End, and Empty Element Tags......Page 38 2.5.8 Comments......Page 39 2.5.10 CDATA Sections......Page 40 2.6.1 Entity Declarations......Page 41 2.6.2 Element Type Declarations......Page 43 2.6.2.1 Content models......Page 44 2.6.3.1 Attribute data types......Page 46 2.6.3.2 Attribute values and constraints......Page 47 2.7.1 The Canonical XML Data Model......Page 49 2.8.1 XML Namespaces......Page 50 2.8.4 Communicating with XML Protocols......Page 51 2.8.6 Transforming XML with XSLT......Page 52 3.1 The Birth of SAX......Page 53 3.2 Understanding SAX......Page 54 Figure 3-1. Components of a SAX application......Page 55 3.2.2.2 ErrorHandler......Page 56 3.2.2.4 EntityResolver......Page 57 3.2.3 SAX Reader Objects......Page 58 3.3.1 Writing a Simple Handler......Page 59 3.3.3 Adding Intelligence......Page 60 3.3.4 Using the Additional Information......Page 62 3.4.1 Creating the Index Generator......Page 63 3.4.1.1 Creating the IndexFile class......Page 64 Example 3-4. index.py......Page 66 3.4.1.2 Running index.py......Page 68 3.4.2 Searching the Index......Page 69 Example 3-5. saxfinder.py......Page 70 3.5 Building an Image Index......Page 71 3.5.1 Creating Thumbnail Images......Page 72 3.5.2 Implementing the SAXThumbs Handler......Page 73 Example 3-6. saxthumbs.py......Page 74 Example 3-7. thumbmaker.py......Page 75 3.6 Converting XML to HTML......Page 76 Example 3-8. genxml.py......Page 77 3.6.1 The Generated Document......Page 79 3.6.2 The Conversion Handler......Page 80 3.6.3 Driving the Conversion Handler......Page 81 3.7 Advanced Parser Factory Usage......Page 82 3.8.1 Using PyExpat Directly......Page 83 Chapter 4. The Document Object Model......Page 85 4.1 The DOM Specifications......Page 86 4.1.1 Levels of the Specification......Page 87 4.1.2 Feature Specifications......Page 88 4.2 Understanding the DOM......Page 89 4.3 Python DOM Offerings......Page 90 4.3.3 4DOM: A Full Implementation......Page 91 4.4.1.2 Loading a document using minidom......Page 92 4.4.3 Getting a Node's Children......Page 93 4.4.4 Getting a Node's Siblings......Page 94 Example 4-1. po.xml......Page 95 Example 4-3. textme.py......Page 96 4.4.7 Looking at Attributes......Page 97 4.5.1 Creating New Nodes......Page 98 Example 4-4. domit.py......Page 99 Example 4-5. domit2.py......Page 101 4.6.1 Preparing the Web Server......Page 102 4.6.1.2 Enabling write permission......Page 103 4.6.2.1 The Article class......Page 104 Example 4-6. Article class from article.py......Page 106 4.6.2.2 The Storage class......Page 107 Example 4-7. storage.py......Page 108 4.6.3.1 The ArticleManager class......Page 109 Example 4-8. ArticleManager.py......Page 111 4.6.4 Controlling the Application......Page 112 Example 4-9. start.cgi......Page 114 Chapter 5. Querying XML with XPath......Page 115 5.3 Location Paths......Page 116 Example 5-1. ships.xml......Page 117 Example 5-2. xp.py......Page 118 5.3.4 Specifying an Index......Page 119 5.3.5 Testing Descendent Nodes......Page 120 5.3.6 Testing Attributes......Page 121 5.3.8 Additional Operators......Page 122 Example 5-4. products.xsl......Page 123 5.5.1 Working with Numbers......Page 124 Figure 5-1. Using the sum( ) XPath function......Page 125 5.5.2 Working with Strings......Page 126 5.5.3 Working with Nodes......Page 127 5.6 Compiling XPath Expressions......Page 128 Chapter 6. Transforming XML with XSLT......Page 129 6.2 XSLT Processors......Page 130 6.3 Defining Stylesheets......Page 131 Example 6-1. ships-template.html......Page 132 Example 6-2. ships.html......Page 133 Example 6-3. ships.xsl......Page 134 Example 6-4. ships2.html......Page 135 6.4 Using XSLT from the Command Line......Page 136 6.5.1 The Stylesheet Element......Page 137 6.5.2 Creating a Template Element......Page 138 6.5.3 Applying Templates......Page 139 6.5.4 Getting the Value of a Node......Page 142 6.5.5 Iterating over Elements......Page 143 6.6.1 File Template......Page 144 6.6.3 Method Template......Page 145 Example 6-5. pyxml.xsl......Page 146 6.7.2 Creating a Simple Stylesheet......Page 147 Figure 6-3. Transformation using a simple stylesheet......Page 148 Example 6-7. edstory.xsl......Page 149 6.7.4 Creating the CGI Script......Page 150 6.7.5 Selecting a Mode......Page 151 Example 6-8. xslt.cgi......Page 152 Chapter 7. XML Validation and Dialects......Page 153 Example 7-1. product.xml with a bad product element......Page 154 Example 7-3. order.dtd......Page 156 7.2 Validation at Runtime......Page 157 Example 7-5. A DTDHandler class implements DTDConsumer in xpHandlers.py......Page 158 7.3 The BillSummary Example......Page 159 7.3.1 The Flat File......Page 160 7.3.2 The Web Form......Page 161 Example 7-8. The web form flatfile.html will post your flat file......Page 162 Figure 7-1. A web form hosts a flat text file......Page 163 Example 7-9. flatfile.cgi, a first step version of the CGI......Page 164 7.3.4.1 Converting text to XML......Page 165 Example 7-10. FlatfileParser.py......Page 168 Example 7-11. A well-formed, converted, valid, BillSummary.xml......Page 169 Example 7-12. BillSummary.dtd......Page 170 Example 7-13. ValidityError.py......Page 171 7.3.5.1 Defining success and error functions......Page 172 7.3.5.2 Converting the flat file to XML......Page 173 7.3.5.3 Validating the converted XML......Page 174 7.3.5.4 Displaying the XML......Page 175 Example 7-14. flat2xml.cgi......Page 176 Figure 7-4. A run of flat2xml.cgi with excessive validation errors......Page 178 7.5.1 ebXML Document Structure......Page 180 7.5.3 Phases of ebXML......Page 181 8.1.1 Continuing Improvement......Page 182 8.2 Working with URLs......Page 183 8.2.1 Encoding URLs......Page 184 8.3 Opening URLs......Page 185 8.3.2 Retrieving URLs......Page 186 Example 8-1. retrieve.py......Page 187 8.4.1 HTTP Conversations......Page 188 8.4.2 Request Types......Page 189 8.4.3 Getting a Document with Python......Page 190 Example 8-2. Making an HTTP Request......Page 191 8.4.5 Baking Cookies for the Server......Page 192 8.4.6.2 Ensuring proper URL encoding......Page 193 8.4.6.3 Performing a POST with httplib......Page 194 Example 8-4. post.py......Page 195 8.5 Using the Server Classes......Page 196 8.5.1 BaseHTTPServer Module Classes......Page 197 8.5.2.2 Serving a GET......Page 198 8.5.2.3 Serving a POST......Page 199 Example 8-5. HTTPServer.py......Page 200 Figure 8-1. A browser connecting to the server with a GET request.......Page 202 Figure 8-2. A web form to test the server......Page 203 Figure 8-3. A response to a submitted form......Page 204 Chapter 9. Python, Web Services, and SOAP......Page 205 9.2.1 SOAP Messages......Page 206 9.2.2 Exchanging SOAP Messages......Page 207 9.2.4.1 SOAP packet requirements......Page 208 9.2.5 Using SOAP Headers......Page 209 9.2.7.1 Fault element......Page 210 9.2.8 SOAP Encoding Techniques......Page 211 9.2.9 SOAP Encoding Rules......Page 212 9.2.12 SOAP over HTTP......Page 213 9.3 Python SOAP Options......Page 214 9.3.1 Working with SOAPy......Page 215 9.3.3.1 Adding URIs and namespaces......Page 216 9.3.3.2 Creating the SOAP envelope......Page 217 9.4.1 Requirements for Using MSSOAP......Page 218 9.4.1.3 Getting Python COM support......Page 219 Figure 9-1. Selecting the SOAP Type Library with makepy.py......Page 220 9.4.3 A Python SOAP Client......Page 221 9.4.3.1 Defining reusable basics......Page 222 Example 9-1. PyCalcSerial.py......Page 224 Chapter 10. Python and Distributed Systems Design......Page 226 10.1.1 Decoupling Application Systems......Page 227 10.2 Understanding the Scope......Page 228 10.3.1 Creating a Profiles Database......Page 229 10.3.3 Populating the Database......Page 230 Example 10-1. popdb.py......Page 231 10.4 Building the Profiles Access Class......Page 232 10.4.1 The Interfaces......Page 233 10.4.2 Getting Profiles......Page 234 10.4.2.2 Building the XML document......Page 235 10.4.3 Inserting and Deleting Profiles......Page 237 10.4.3.1 Inserting a profile......Page 238 10.4.4 Updating Profiles......Page 240 10.4.5 The Complete CustomerProfile Class......Page 241 Example 10-2. CustomerProfile.py......Page 242 10.5 Creating an XML Data Store......Page 245 Example 10-3. OfferXMLStore.xml......Page 246 10.5.2.1 The interfaces......Page 247 10.5.2.2 Using the XMLOffer class......Page 248 10.5.2.3.1 Retrieval methods......Page 249 10.5.2.3.2 Modification methods......Page 250 Example 10-4. XMLOffer.py......Page 251 10.6 The XML Switch......Page 253 10.6.2 Core XML Switch Classes......Page 254 Example 10-5. An example message.xml file......Page 255 Example 10-6. runxm.py -- using the XMLMessage object......Page 256 10.6.3.3 XML message code architecture......Page 258 Example 10-7. XMLMessage.py......Page 259 10.6.4 The XML Switch Service......Page 261 Example 10-8. The postMsg.html file......Page 262 Figure 10-2. Using postMsg.html to connect to the server......Page 263 10.6.5.2 Using the XSC client......Page 264 Example 10-10. Running xcs.py from the command line......Page 265 Example 10-11. xsc.py, the client to the XML Switch......Page 266 10.6.6.1 XMLSwitchHandler code architecture......Page 268 Example 10-12. XMLSwitchHandler.py......Page 270 Example 10-13. The XML Switch launching script: runxs.py......Page 274 Figure 10-4. A detail of the web application......Page 275 10.8.3 The Topology......Page 276 Figure 10-5. intro.html is the start page for the CGI example......Page 277 10.8.5 The CGI Functionality......Page 278 10.8.5.1 Extracting profile information......Page 280 Figure 10-6. The profile-editing form......Page 281 10.8.5.2 Updating profile information......Page 282 10.8.5.3 Displaying all offers......Page 283 Example 10-15. sp.py......Page 284 Appendix A. Installing Python and XML Tools......Page 288 A.1.2 Linux and Unix......Page 289 A.2 Installing PyXML......Page 290 A.3 Installing 4Suite......Page 291 Example B-1. gen-td.py—a script to print XML defi......Page 292 Figure B-1. termdef.html loaded in a browser......Page 293 B.1 XML Definitions......Page 294 Appendix C. Python SAX API......Page 302 Appendix D. Python DOM API......Page 314 Node Constants......Page 320 Node Properties and Methods......Page 321 D.1 4DOM Extensions......Page 332 E.2 Basic DOM Operations......Page 333 Example E-1. books.xml......Page 334 E.2.2 Using a NodeList......Page 335 Example E-3. nodelists.py......Page 336 E.3.2 XSL Stylesheet......Page 337 Example E-5. temps.xsl......Page 338 Example E-6. transform.py......Page 339 E.4 Handling Parsing Errors......Page 340 E.5 MSXML3.0 Reference......Page 341 MSXML3.0 Document Object Methods......Page 342 MSXML3.0 Document Object Properties......Page 343 MSXML3.0 Node Object Methods......Page 345 MSXML3.0 Node Object Properties......Page 346 F.1 Pyxie......Page 351 F.3 XML Schema Validator......Page 353 F.6.2 Page Templates......Page 354 Colophon......Page 355 About the Author......Page 357 If you are a Python programmer who wants to incorporate XML into your skill set, this is the book for you. Python has attracted a wide variety of developers, who use it either as glue to connect critical programming tasks together, or as a complete cross-platform application development language. Yet, because it is object-oriented and has powerful text manipulation abilities, Python is an ideal language for manipulating XML.Python & XML gives you a solid foundation for using these two languages together. Loaded with practical examples, this new volume highlights common application tasks, so that you can learn by doing. The book starts with the basics then quickly progresses to complex topics, like transforming XML with XSLT, querying XML with XPath, and working with XML dialects and validation. It also explores the more advanced issues: using Python with SOAP and distributed web services, and using Python to create scalable streams between distributed applications (like databases and web servers).The book provides effective practical applications, while referencing many of the tools involved in XML processing and Python, and highlights cross-platform issues along with tasks relevant to enterprise computing. You will find ample coverage of XML flow analysis and details on ways in which you can transport XML through your network.Whether you are using Python as an application language, or as an administrative or middleware scripting language, you are sure to benefit from this book. If you want to use Python to manipulate XML, this is your guide. If you are a Python programmer who wants to incorporate XML into your skill set, this is the book for you. Python has attracted a wide variety of developers, who use it either as glue to connect critical programming tasks together, or as a complete cross-platform application development language. Yet, because it is object-oriented and has powerful text manipulation abilities, Python is an ideal language for manipulating XML.__Python & XML__The book provides effective practical applications, while referencing many of the tools involved in XML processing and Python, and highlights cross-platform issues along with tasks relevant to enterprise computing. You will find ample coverage of XML flow analysis and details on ways in which you can transport XML through your network.Whether you are using Python as an application language, or as an administrative or middleware scripting language, you are sure to benefit from this book. If you want to use Python to manipulate XML, this is your guide.
دانلود کتاب Python and XML: Includes index