<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>PHPDeveloper.org</title>
    <link>http://www.phpdeveloper.org</link>
    <description>Up-to-the Minute PHP News, views and community</description>
    <language>en-us</language>
    <pubDate>Thu, 24 May 2012 20:25:35 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Working Software Blog: Escaping single and double quotes for use with XPath queries in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/16746</guid>
      <link>http://www.phpdeveloper.org/news/16746</link>
      <description><![CDATA[<p>
On the Working Software blog there's a new post showing a solution to a issue with <a href="http://www.workingsoftware.com.au/page/Escaping_single_and_double_quotes_in_XPath_queries_in_PHP">escaping quotes in XPath queries</a> that's not just an issue in PHP.
</p>
<blockquote>
I've been working with the Basecamp API to plugin our IRC bot that we use for time tracking and I'm astounded to learn that escaping single and/or double quotes for XPath queries in PHP does not have a well documented, best practices solution. In fact, it seems as though this is not peculiar to PHP. I took a look around and found this excellent article by "Kushal": <a href="http://kushalm.com/the-perils-of-xpath-expressions-specifically-escaping-quotes">http://kushalm.com/the-perils-of-xpath-expressions-specifically-escaping-quotes</a>.
</blockquote>
<p>
He's put together <a href="https://gist.github.com/1155973">his own (PHP) solution</a> to the problem - running the entire XPath query through a filtering method that splits it up, replaces the quote characters and combines it back down to a single string.
</p>]]></description>
      <pubDate>Fri, 19 Aug 2011 13:50:14 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Script-Tutorials.com: How to parse web pages using XPath]]></title>
      <guid>http://www.phpdeveloper.org/news/16228</guid>
      <link>http://www.phpdeveloper.org/news/16228</link>
      <description><![CDATA[<p>
On the Script-Tutorials.com site there's a new article showing you how to <a href="http://www.script-tutorials.com/how-to-parse-web-pages-using-xpath/">use XPath to parse web pages</a>, complete with screenshots of the page and the code to make it happen.
</p>
<blockquote>
Today I will tell you how you can make parsers of remote HTML pages (in PHP). In this article I will show you how to perform xpath queries to Web pages. XPath - a query language to elements of xml or xhtml document. To obtain the necessary data, we just need to create the necessary query. For the work, we also need: browser Mozilla Firefox, <a href="https://addons.mozilla.org/en-us/firefox/addon/firebug/">firebug</a> and <a href="https://addons.mozilla.org/ru/firefox/addon/firepath/">firepath</a> plugins. For our experiment, I suggest this webpage <a href="http://news.google.com/news/section?pz=1&cf=all&topic=t&ict=ln">Google Sci/Tech News</a>. Of course you can choose any other web page too.
</blockquote>
<p>
They provide <a href="http://www.script-tutorials.com/demos/59/index.php">two</a> <a href="http://www.script-tutorials.com/demos/59/index-2.php">demos</a> and a <a href="http://www.script-tutorials.com/demos/59/source.zip">downloadable package</a> with everything you need. The script pulls in the page as a DOM document (which works as long as it's correctly formatted XML) and spits back out the matches from a few different XPath expressions. There's <a href="http://www.google.com/#q=xpath+examples">all sorts of sites</a> out there that can help you with examples of other XPath expressions and syntax.
</p>]]></description>
      <pubDate>Thu, 21 Apr 2011 09:49:59 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Qafoo.com: Practical PHPUnit: Testing XML generation]]></title>
      <guid>http://www.phpdeveloper.org/news/15150</guid>
      <link>http://www.phpdeveloper.org/news/15150</link>
      <description><![CDATA[<p>
On the Qafoo blog today there's a new post from <i>Tobias Schlitt</i> about a method you can use to <a href="http://qafoo.com/blog/007_practical_phpunit_testing_xml_generation.html">unit test methods that generate XML</a> without messing with a lot of extra overhead just to test the results.
</p>
<blockquote>
Testing classes which generate XML can be a cumbersome work. At least, if you don't know the right tricks to make your life easier. In this article, I will throw some light upon different approaches and show you, how XML generation can be tested quite easily using XPath.
</blockquote>
<p>
He includes a sample class, qaPersonVisitor, that has methods inside it to create a simple XML documents based on the first and last name data into a DOM element. He sets up the basic test case that creates a simple person - including gender and date of birth - and offer a few different suggestions on handling the check (in <a href="http://phpunit.de">PHPUnit</a> tests):
</p>
<ul>
<li>the naive way of rebuilding the DOM object and assert that they are equal
<li>testing the resulting XML from the DOM object against a pre-generated XML document
<li>matching the contents via CSS selectors
<li>using the tag matching assertions
<li>using XPath in a custom assertion (with short and long uses of it included)
</ul>]]></description>
      <pubDate>Fri, 17 Sep 2010 13:51:02 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Thomas Weinert's Blog: Using PHP DOM With XPath]]></title>
      <guid>http://www.phpdeveloper.org/news/14342</guid>
      <link>http://www.phpdeveloper.org/news/14342</link>
      <description><![CDATA[<p>
<i>Thomas Weinert</i> has a recent post to his blog showing <a href="http://www.a-basketful-of-papayas.net/2010/04/using-php-dom-with-xpath.html">how to use</a> one of the more powerful XML-handling features that PHP's DOM extension includes - XPath.
</p>
<blockquote>
Often I hear people say "We use SimpleXML, because DOM is so noisy and complex". Well, I don't think so. This article explains how you can parse a XML (an Atom feed) using the PHP DOM extension. No other libraries are involved.
</blockquote>
<p>
In his example he loads an external feed (his own) into a DOM object, blocks any errors with a few handy functions and creates a DOMXPath object on the DOM object to get ready for his queries. He shows how to make searches for titles, subtitles, looping over attributes and an element list returned from one of the first queries. A full code listing is also provided to show how it all fits together.
</p>]]></description>
      <pubDate>Tue, 13 Apr 2010 13:18:32 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPBuilder.com: Build a PHP Link Scraper with cURL ]]></title>
      <guid>http://www.phpdeveloper.org/news/13850</guid>
      <link>http://www.phpdeveloper.org/news/13850</link>
      <description><![CDATA[<p>
On PHPBuilder.com today there's <a href="http://www.phpbuilder.com/columns/marc_plotz011410.php3">a new tutorial</a> posted about building a link scraping script with the combination of PHP and <a href="http://curl.haxx.se/">cURL</a> (the script pulls in a page, grabs all of the links off of it and follows them, etc).
</p>
<blockquote>
I actually built this a few years ago because I had grandiose visions of becoming the next Google. Clearly, that did not happen, mostly because my localhost, database, and bandwidth are not infinite. Yet this little robot has quite interesting applications and uses if you really have the time to play with and fine-tune it.
</blockquote>
<p>
You'll need to have <a href="http://php.net/curl">cURL support</a> built into your PHP installation to get the scripts working, but the actual code itself is pretty simple. Curl and XPath do most of the heavy lifting of finding and following the links and its easy enough to drop them into a MySQL table from there. You can <a href="http://www.phpbuilder.com/columns/PHP_LinkScraper_source.zip">download the source here</a>.
</p>]]></description>
      <pubDate>Fri, 15 Jan 2010 10:02:45 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Juozas Kaziukenas' Blog: Web scraping with PHP and XPath]]></title>
      <guid>http://www.phpdeveloper.org/news/11972</guid>
      <link>http://www.phpdeveloper.org/news/11972</link>
      <description><![CDATA[<p>
In <a href="http://dev.juokaz.com/php/web-scraping-with-php-and-xpath">this new post</a> to his blog <i>Juozas Kaziukenas</i> takes a look at one method for getting the information out of a remote page - parsing it with PHP and XPath (assuming the page is correctly formatted).
</p>
<blockquote>
When I was writing about <a href="http://dev.juokaz.com/php/web-scraping-easy-way-to-monitor-market">how I use web scraping</a>, I was still hadn't tried using Xpath (shame on me). [...] It turned out, that using Xpath is extremely easy, really. When you master it, you can do everything in seconds. Yes, you need to know how XML works and how to write correct Xpath queries (brief explanation of Xpath syntax is available at <a href="http://www.w3schools.com/XPath/xpath_syntax.asp">W3Schools</a>), but hey - these topics are in 1st year of university. 
</blockquote>
<p>
He includes both some sample code (to fetch a titles and prices for cameras from bhphotovideo.com) and a link to a <a href="https://addons.mozilla.org/en-US/firefox/addon/1095">XPath checker</a> you can use to ensure that your query is correctly formatted. It's good that he also includes a quick reminder about the ethical issue with web scraping - it could be considered stealing depending on where the information comes from and who is providing it.
</p>]]></description>
      <pubDate>Wed, 18 Feb 2009 10:28:08 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Community News: XPath Explained (by Tobias Schlitt and Jacob Westhoff)]]></title>
      <guid>http://www.phpdeveloper.org/news/11937</guid>
      <link>http://www.phpdeveloper.org/news/11937</link>
      <description><![CDATA[<p>
<i>Tobias Schlitt</i> and <i>Jacob Westhoff</i> have written up and article (and posted it <a href="http://schlitt.info/opensource/blog/0704_xpath.html">over on Tobias' blog</a>) that wants to help you understand XPath better - whether you're a novice or have been using it for a while.
</p>
<blockquote>
This paper will give an overview on XPath an addressing language for XML documents. XPath is a W3C recommendation currently in version 1.0. XPath was created in relation to the XSL recommendation and is intended to be used with XSLT and XPointer. Beside that, XPath can be used in a variety of programming languages, commonly in combination with a DOM API.
</blockquote>
<p>
The article starts with an <a href="http://schlitt.info/opensource/blog/0704_xpath.html#introduction">introduction to the concept</a> of XPath, moves on to <a href="http://schlitt.info/opensource/blog/0704_xpath.html#addressing">addressing</a>, talks about <a href="http://schlitt.info/opensource/blog/0704_xpath.html#xpath-axes">XPath axes</a>, mentions <a href="http://schlitt.info/opensource/blog/0704_xpath.html#functions-operators-and-conditions">functions/operators/conditions</a> and looks at <a href="http://schlitt.info/opensource/blog/0704_xpath.html#xpath-and-xslt">styling XML with XPath and XSLT</a>.
</p>]]></description>
      <pubDate>Thu, 12 Feb 2009 10:28:04 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[PHP in Action: Get links with XPath]]></title>
      <guid>http://www.phpdeveloper.org/news/11157</guid>
      <link>http://www.phpdeveloper.org/news/11157</link>
      <description><![CDATA[<p>
In response to <a href="http://www.phpro.org/examples/Get-Links-With-DOM.html">this tutorial</a> over on the PHPro.org website a <a href="http://www.reiersol.com/blog/1_php_in_action/archive/162_get_links_with_xpath.html">new post</a> has been made to the PHP in Action blog with an "even cooler" way to do the same sort of DOM fetching - XPath.
</p>
<blockquote>
I'm a little bit surprised at the claim [the tutorial makes] that it's the "correct" (only) way, since there's at least one more that I find even cooler: XPath. Admittedly, it's slower, yet it's a more powerful language. 
</blockquote>
<p>
A <a href="http://www.reiersol.com/blog/1_php_in_action/archive/162_get_links_with_xpath.html">quick example</a> is included, building up from a simple search for anchor tags up to a custom query looking for just the anchor tags with a class of "bookmark".
</p>]]></description>
      <pubDate>Tue, 07 Oct 2008 08:43:33 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Debuggable Blog: XPath on PHP Arrays (Set::extract)]]></title>
      <guid>http://www.phpdeveloper.org/news/11096</guid>
      <link>http://www.phpdeveloper.org/news/11096</link>
      <description><![CDATA[<p>
On the Debuggable blog there's <a href="http://debuggable.com/posts/xpath-on-php-arrays-set-extract:48ca6265-258c-4032-b3ff-55b84834cda3">an interesting post</a> where <i>Felix</i> talks a bit about something I've seen requested quite a bit - a method for locating information in an array. His answer is an XPath-style query system to root out your custom information.
</p>
<blockquote>
One of the requirements [of the original Set::extract method] was that the new method would need to be faster or at least as fast as the old implementation. My first attempts were big failures. Not only did the solutions I came up with contain tons of bugs. No, they were are also a lot slower the old extract function. A few benchmarks later and I discovered the biggest bottleneck in my implementation: Recursiveness.
</blockquote>
<p>
He notes that no doing things recursively (not just in this situation, but ever) can help with a speed boost. In his example, a small change made all the differences and the <a href="https://trac.cakephp.org/browser/branches/1.2.x.x/cake/libs/set.php#L334">XPath implementation</a> in the CakePHP core makes grabbing information from any array simple.
</p>
<blockquote>
While the implementation does not support full XPath (and probably won't in future), feel free to make suggestions on additional selectors or the idea in general.
</blockquote>]]></description>
      <pubDate>Fri, 26 Sep 2008 10:25:23 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Chris Hartjes' Blog: Reader Feedback: Working with XML In PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/10916</guid>
      <link>http://www.phpdeveloper.org/news/10916</link>
      <description><![CDATA[<p>
<i>Chris Hartjes</i> has <a href="http://www.littlehart.net/atthekeyboard/2008/08/27/reader-feedback-working-with-xml-in-php/">answered some more questions</a> his readers have asked in a new post to his blog today. This time the focus is on XML handling.
</p>
<blockquote>
Welcome to the 3rd installment of me answering reader feedback questions. Today we deal with a topic that I deal with every day at my <a href="http://www.xmlteam.com/">day job</a> - working with XML in PHP.
</blockquote>
<p>
He <a href="http://www.littlehart.net/atthekeyboard/2008/08/27/reader-feedback-working-with-xml-in-php/">talks about</a> SimpleXML (and how well it does its job) and their (his work's) current method of handling the storage of XML in a database. He describes both their current process and his ideal one, how he'd want to interface with their <a href="http://www.littlehart.net/atthekeyboard/2008/08/27/reader-feedback-working-with-xml-in-php/exist.sourceforge.net">eXist</a> backend.
</p>]]></description>
      <pubDate>Thu, 28 Aug 2008 09:39:07 -0500</pubDate>
    </item>
  </channel>
</rss>

