Please create an account to participate in the Slashdot moderation system

 



Forgot your password?
typodupeerror
×

No Nonsense XML Web Development with PHP 131

Alex Moskalyuk writes "PHP and XML seems like a marriage made in heaven. Powerful manipulation functions and support on the core language level in PHP5 combined with universal extensibility of XML make it a technology of choice for quite a few Web enthusiasts and companies out there. However, anyone inspired by PHP's ease of use can probably find a good cure from insomnia when facing with XML specs. With all the DTD's, XML Schemas, XSLT and XPath queries one can easily get the impression that the world is changing on them, and perhaps sticking to hard-coded HTML with PHP statements combined with SQL statements for data retrieval would be within the zone of comfort." Read the rest of Alex's review.
No Nonsense XML Web Development with PHP
author Thomas Myer
pages 354
publisher SitePoint
rating 9/10
reviewer Alex Moskalyuk
ISBN 097524020X
summary XML, XSLT, XPath and DOM primer for PHP developers


Thomas Myer's No Nonsense XML Web Development with PHP is an XML primer for those who have been exposed to PHP, but are yet waiting to appreciate the elegance of PHP+XML solutions. Throughout 10 chapters and 2 appendices Myer is introducing the reader to different aspects of XML, their best-practice implementations in LAMP (where last P stands for PHP) environment, and their relevance to the real world. For the real-world example Myer decides to guide the reader through writing a custom content management system - complete with publishing/admin interface, templating/presentation layer, search engine, RSS feeds and other commonly expected features.

The book is not an introduction to PHP, but it does assume that the Web developer knows what XML is, but has never dealt with it. So the first chapter just talks about properly parsing XML with IE and Firefox, validating an XML document, differences between a well-formed and a valid XML document. Overall, it provides a very good introduction to XML for someone who has never dealt with it, and could probably be skipped by developers with XML exposure.

Chapter 2, XML in Practice, goes into nitty-gritty details of XML, and 26 pages later the reader knows how to create an XML file to display in the browser, declare proper namespaces, attach a CSS file to existing XML file and display the proper XML+CSS file (look, Ma, no <html>!) in the browser. The author earns instant geek credibility by displaying Firefox screenshots, with the exception of IE screenshot whenever IE is discussed. At the end of the chapter the author takes us through the basic XSLT.

DTD's, XSLT and writing a practical PHP app take up the next three chapters, followed by XML manipulation chapters. JavaScript enthusiasts will probably find Chapter 6 pretty useful, as it discusses manipulating XML on the client side, working with XSLT, and creating dynamic site navigation based on the XML source. Chapter 7 is what one would expect from the book that has the words PHP and XML in the title - discussion of SAX, DOM and SimpleXML parsers, examples of their implementation, discussion of proper use cases for each one of the technologies. The SimpleXML subchapter also contains a good primer on XPath - a query language that allows the developer to provide the parser with a query to navigate down the XML document.

Chapter 8 takes the reader through RDF and RSS, discusses the ways the syndication feeds are used on the Web nowadays. Since throughout all these chapters we're building a content management system, this is the right time to add the RSS headlines functionality to the site. The next chapter discusses another practical implementation of XML on the Web - XML-RPC calls between the sites and proper ways of exchanging data via XML Web services. The chapter discusses SOAP, although not a whole lot, and just mentions REST as another way to implement Web Services. As a practical exercise, the author takes readers on a tour of building an XML-RPC client, server and connecting those two together.

The last chapter talks about using XML with databases. Native XML databases are discussed, but let's face it - most of the PHP development is done with relational databases anyway. Myer talks about exporting MySQL database contents into XML with phpMyAdmin and mysqldump. The first appendix includes function reference for SAX, DOM and SimpleXML parsing in PHP, while the second one completes the CMS project by providing the rest of the necessary files.

I found the author's style very easy to follow and approachable. The code samples are succinct and to the point, there are also no generic discussions, such as "Why PHP?" The project chosen for the practical implementation is a bit boring, but at the same time quite real-world. The screenshots are clear, and code examples are nicely highlighted. The errata is provided on the book Web site. Code archive is available as a single file download as well. The book site also provides 100% money back guarantee (less shipping and handling fees) to anyone who bought the title, and didn't feel like they were getting their money's worth.

However, there are a few drawbacks that I noticed as well. With topics like XSLT and XPath broken into several chapters and discussed in smaller chunks, it's hard to use the book as a reference later on. Appendix A with PHP function reference for XML parsing hardly seems like a worthy addition, since PHP manual page on the subject contains equivalent information with more real-life examples contributed by users.

With all that, the book is quite informative, educational and useful. The author manages to tackle quite a few difficult topics in 260 pages provided to him (the count excludes preface and appendices). However, kudos to the author for writing chapters on XML without sounding boring, redundant or too academic. I would highly recommend this book to anyone interested in developing PHP-driven Web sites that provide or consume Web services, work with XML data or generate XML for others to use."


You can purchase No Nonsense XML Web Development with PHP from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
This discussion has been archived. No new comments can be posted.

No Nonsense XML Web Development with PHP

Comments Filter:
  • Code Download (Score:5, Informative)

    by saberworks ( 267163 ) on Wednesday March 15, 2006 @01:56PM (#14925679)
    I tried to download the code examples but the site is asking me for a special code that is printed inside the book. Bleh.
  • by icklemichael ( 521080 ) on Wednesday March 15, 2006 @02:00PM (#14925707)

    Any recent install of java will almost certainly have an xslt processor on it, you just have to remember the magic incantation:

    java org.apache.xalan.xslt.Process -XSL [template] -IN [file]
  • Re:Code Download (Score:3, Informative)

    by twitchkat ( 566638 ) on Wednesday March 15, 2006 @02:19PM (#14925890) Homepage
    <?php

    $f = fopen('/usr/share/dict/words');

    while ($w = readline($f))
        {
        $c = curl_init();
        curl_setopt($c, CURLOPT_URL, 'http://www.sitepoint.com/books/xml1/code.php');
        curl_setopt($c, CURLOPT_POST, 1);
        curl_setopt($c, CURLOPT_POSTFIELD, array ('word1'=>$w,
    'boughtfrom'=>'amazon',
    'country'= >'US',
    'email'=>'foo@bar.com',
    'submit'=>'Downlo ad Code Archive'));

        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
        $r = curl_exec($c);
        curl_close($c);

        if (strstr($r, 'Code Word'))
          {
          continue;
          }

        write_to_file('result.zip', $r);
        }

    ?>
  • Re:wut (Score:2, Informative)

    by demon411 ( 827680 ) on Wednesday March 15, 2006 @02:22PM (#14925917)
    I agree. XML is no more than a text file with key/value pairs in some form of organization.

    That's a common misconception of what XML is. XML typically refers to XML and related technologies

    1. DTD - Document Type Definitions
    2. XML Schema
    3. XSL/XSLT - Extensible Stylesheet Language, XSL Transforms
    4. Xpath - XML Path Language
    5. XHTML - XML Version of HTML
    6. XQL - XML Query Language
    7. XSP - XML Server Pages
    8. Others
  • Agreed.
    XML is designed to be an exchange format.
    Databases are designed to hold and maintain data.
    Applications are designed to present and modify the data.

    My database talks to my application which talks in XML to talk to your application to talk to your database.

    XML/XSLT is more work than it is worth because it is forcing the squre block into the round hole with a hammer. XSLT is for converting somebody else's XML into the XML your application wants to consume.
    If you have a limited number of users of your raw data, you can just as easily talk to them and give them a simple CSV or TSV file and move on with live.

    IMarv
  • Re:wut (Score:4, Informative)

    by Cereal Box ( 4286 ) on Wednesday March 15, 2006 @02:34PM (#14926023)
    The beauty of XML is that the format is simple and there is a huge stack of technologies that build on it. If you store some data in an XML format, you instantly have the ability to transform you data into any number of formats (via arbitrarily-complex XSL transforms), perform automatic validation (via XML schema or a DTD), perform arbitrarily-complex queries on your data (via XPath/XQuery), automatically include other resources (XInclude), etc. Thanks to namespace support, you can aggregate multiple XML data formats into a single document -- an example of which is XHTML, which allows a single web page to include things like mathematical annotations (MathML), vector graphics (SVG), multimedia (SMIL), complicated input forms (XForms), and so on. Like so many other people, you just see XML as a substitute for comma separated value files, and don't realize the rich set of complicated functionality that's available to you "for free" just by storing your data in an XML format.

    And BTW, XML is a tree format, not strictly key/value. And when you parse an XML file, you're never having to do direct text manipulation (which is error-prone). You're either receiving the information stored in the XML file as a series of events (SAX) or you're manipulating it via an object model (DOM).
  • by Heembo ( 916647 ) on Wednesday March 15, 2006 @02:45PM (#14926133) Journal
    Not only that, but most Java/J2EE developers have been XML'ing as a core part of the language for many years. This posting seems a bit off (like as in, 3 years off) to me...
  • Re:wut (Score:4, Informative)

    by Bogtha ( 906264 ) on Wednesday March 15, 2006 @02:57PM (#14926250)

    I think the parenthetical version and the XML version are about equal in terms of readability once you remember that any decent editor will have syntax highlighting to emphasise the text over the tags and that both versions will typically be split over multiple lines. Linebreaks don't really aid readability when you have short ending delimiters, but they do when you have longer ending delimiters.

    The idea that XML is just a reinvention of s-expressions is quite popular, but this article [prescod.net] does a decent job of explaining how they differ.

  • by jkeegan ( 35099 ) on Wednesday March 15, 2006 @03:05PM (#14926327) Homepage Journal
    No, it's not just key/value pairs. It's hierarchical. The hierarchy itself contains data - where things are located. You can't express rich hierachical data easily in a flat key/value layout.

    In an XML file, I can throw in extra attributes or elements that won't be read by an old version of an app that wasn't looking for them. In a simple comma-separated-values layout, if I add something to the format, it's completely incompatible with previous versions.

    The most complicated tools you have for comma-separated values are along the lines of cut and sed. When you have an XML document, you can convert it to *any* other XML format with a simple XSLT stylesheet (or, for that matter, into non-XML formats). SQL-Select-like statements can be represented with XPath, letting you select various fields of nodes which contain a certain attribute, act on the a certain way, etc.

    Any anyway, would you look at an HTML document and say "it's just key-value pairs"? No! The order of elements, the hierarchy of data, etc, all makes up the page as a whole. HTML was an application of SGML, which XML was derived from.. Use XHTML if that last bit confuses you - it's not key/value pairs.

    People have thrown the buzzwords at you because they're either really impressed with the technology, or because they're the kind of people that like buzzwords. Ignore the latter group of people, and try to focus on why those of us in the first group are singing its praises.
  • by codergeek42 ( 792304 ) <peter@thecodergeek.com> on Wednesday March 15, 2006 @03:10PM (#14926380) Homepage Journal
    You want mbstring [php.net] which supports, among other things, the UTF-8 incarnation of the Unicode standard.
  • by tiedemann ( 214491 ) on Wednesday March 15, 2006 @04:12PM (#14926905)
    Same with the .NET framework.
    XPath, XQuery and XLST has had really nice implementations since the beginning.
  • by mindlessLemming ( 961508 ) on Wednesday March 15, 2006 @11:06PM (#14929970) Homepage
    This is the most dissapointing PHP book I've read. The 'sample application' built during the course of the book is a complete P.O.S and has so little respect for the concept of instilling best practices early on that beginners are the LAST people I would be recommending this book to.

    Ok, so it's no good for beginner and too basic for anyone else...

    One positive note though -- the introduction to designing and using DTDs is quite good, especially for newbies, but that alone is not worth the price of the book.

    Purchasing this book also resulted in a regular flow of Sitepoint spam until I wrote an abusive email to their marketing department saying that I had most certainly never ticked any of their "Spam me to death" checkboxes and that I couldn't be any less interested in discounts on their books. Surprisingly, their response thanked me for the honest feedback.
    At least it ended well :)

Without life, Biology itself would be impossible.

Working...