PHPDeveloper.orghttp://www.phpdeveloper.org
Up-to-the Minute PHP News, views and communityen-usTue, 31 Mar 2015 15:47:07 -050030http://www.phpdeveloper.org/news/21541http://www.phpdeveloper.org/news/21541
In this new post to his site Thomas Weinert shows how to use the FluentDOM library (a PHP implementation of a Javascript library by the same name) when XML namespaces are involved.

FluentDOM 5 allows to register namespaces on the DOM document class. These are not the namespaces of a loaded document, but a definition of namespaces for your programming logic.

He compares it to both a PHP example, using the DOMXpath handling and a Javascript sample using its own xmlDocument functionality. Finally he compares these examples to the few lines of FluentDOM code to handle the same kind of evaluation. He wraps up the post with a brief mention of the "appendElement" function that wraps serveral operations in one for easy element additions.

Link: http://www.a-basketful-of-papayas.net/2014/08/fluentdom-5-xml-namespaces.html]]>Thu, 07 Aug 2014 10:50:22 -0500http://www.phpdeveloper.org/news/18145http://www.phpdeveloper.org/news/18145
In the latest post to his blog James Morris looks at using XPath's query() function to locate pieces of data in your XML.

The other day I needed to do some html scraping to trim out some repeated data stuck inside nested divs and produce a simplified array of said data. My first port of call was SimpleXML which I have used many times. However this time, the son of a bitch just wouldn't work with me and kept on throwing up parsing errors. I lost my patience with it and decided to give DomDocument and DOMXpath a go which I'd heard of but never used.

He includes a code (and XML document) example showing how to extract out some content from an HTML structure - grabbing each of the images from inside a div and associating them with their description content.

]]>Wed, 27 Jun 2012 10:19:35 -0500http://www.phpdeveloper.org/news/14342http://www.phpdeveloper.org/news/14342
Thomas Weinert has a recent post to his blog showing how to use one of the more powerful XML-handling features that PHP's DOM extension includes - XPath.

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.

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.