Archive for November, 2007

488 CHAPTER 20 (Remote web server) WEB SERVICES simplexml_load_string() object

Friday, November 30th, 2007

488 CHAPTER 20 WEB SERVICES simplexml_load_string() object simplexml_load_string (string data) If the XML document is stored in a variable, you can use the simplexml_load_string() function to read it into the object. This function is identical in purpose to simplexml_load_file(), except that the lone input parameter is expected in the form of a string rather than a file name. simplexml_import_dom() object simplexml_import_dom (domNode node) The Document Object Model (DOM) is a W3C specification that offers a standardized API for creating an XML document, and subsequently navigating, adding, modifying, and deleting its elements. PHP provides an extension capable of managing XML documents using this standard, titled the DOM XML extension. You can use this function to convert a node of a DOM document into a SimpleXML node, subsequently exploiting use of the SimpleXML functions to manipulate that node. SimpleXML Methods Once an XML document has been loaded into an object, several methods are at your disposal. Presently, four methods are available, each of which is introduced in this section. attributes() object simplexml_element->attributes() XML attributes provide additional information about an XML element. In the sample XML document in Listing 20-4, only the author node possesses an attribute, namely gender, used to offer information about the author s gender. You can use the attributes() method to retrieve these attributes. For example, suppose you want to retrieve the gender of each author: book as $book) { echo $book->author.” is “.$book->author->attributes().”.
“; } ?> This example returns: Jane Austen is female. Alberto Moravia is male. Ernest Hemingway is male.
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

CHAPTER 20 WEB SERVICES Note To take (Affordable web hosting)

Wednesday, November 28th, 2007

CHAPTER 20 WEB SERVICES Note To take advantage of SimpleXML, you need to disable the PHP directive zend.ze1_compatibility_mode. simplexml_load_file() object simplexml_load_file (string filename) This function loads an XML file specified by filename into an object. If a problem is encountered loading the file, FALSE is returned. Consider an example: This code returns: object(simplexml_element)#1 (1) { [”book”]=> array(3) { [0]=> object(simplexml_element)#2 (3) { [”title”]=> string(19) “Pride and Prejudice” [”author”]=> string(11) “Jane Austen” [”description”]=> string(32) “Jane Austen’s most popular work.” } [1]=> object(simplexml_element)#3 (3) { [”title”]=> string(14) “The Conformist” [”author”]=> string(15) “Alberto Moravia” [”description”]=> string(46) “Alberto Moravia’s classic psychological novel.” } [2]=> object(simplexml_element)#4 (3) { [”title”]=> string(18) “The Sun Also Rises” [”author”]=> string(16) “Ernest Hemingway” [”description”]=> string(56) “The masterpiece that launched Hemingway’s career.” } } } Note that dumping the XML will not cause the attributes to show. To view attributes, you need to use the attributes() method, introduced later in this section.
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

486 CHAPTER 20 (Web server version) WEB SERVICES You can

Tuesday, November 27th, 2007

486 CHAPTER 20 WEB SERVICES You can also change the default cache location (by default, the same location as the executing script), by modifying the MAGPIE_CACHE_DIR constant: define(’MAGPIE_CACHE_DIR’, ‘/tmp/magpiecache/’); SimpleXML Everyone agrees that XML signifies an enormous leap forward in data management and application interoperability. Yet how come it s so darned hard to parse? Although powerful parsing solutions are readily available, DOM, SAX, and XSLT to name a few, each presents a learning curve that is just steep enough to cause considerable gnashing of the teeth among those users interested in taking advantage of XML s practicalities without an impractical time investment. Leave it to an enterprising PHP developer (namely, Sterling Hughes) to devise a graceful solution. SimpleXML offers users a very practical and intuitive methodology for processing XML structures, and is enabled by default as of PHP 5. Parsing even complex structures becomes a trivial task, accomplished by loading the document into an object and then accessing the nodes using field references, as you would in typical object-oriented fashion. The XML document displayed in Listing 20-4 is used to illustrate the examples offered in this section. Listing 20-4. A Simple XML Document
Jane Austen Jane Austen’s most popular work. Alberto Moravia Alberto Moravia’s classic psychological novel. Ernest Hemingway The masterpiece that launched Hemingway’s career. SimpleXML Functions A number of SimpleXML functions are available for loading and parsing the XML document. Those functions are introduced in this section, along with several accompanying examples.
We recommend high quality webhost to host and run your jsp application: christian web host services.

CHAPTER 20 WEB SERVICES Figure 20-4. Limiting (Web hosting compare)

Monday, November 26th, 2007

CHAPTER 20 WEB SERVICES Figure 20-4. Limiting the number of headlines for each feed Caching Feeds One final topic to discuss regarding Magpie is its caching feature. By default, Magpie caches feeds for 60 minutes, on the premise that the typical feed will likely not be updated more than once per hour. Therefore, even if you constantly attempt to retrieve the same feeds, say once every 5 minutes, any updates will not appear until the feed cache is at least 60 minutes old. However, some feeds are published more than once an hour, or the feed might be used to publish somewhat more pressing information. (RSS feeds don t necessarily have to be used for browsing news headlines; you could use them to publish information about system health, logs, or any other data that could be adapted to its structure. It s also possible to extend RSS as of version 2.0, but this matter is beyond the scope of this book.) In such cases, you may want to consider modifying the default behavior. To completely disable caching, disable the constant MAGPIE_CACHE_ON, like so: define(’MAGPIE_CACHE_ON’, 0); To change the default cache time (measured in seconds), you can modify the constant MAGPIE_CACHE_AGE, like so: define(’MAGPIE_CACHE_AGE’,1800); Finally, you can opt to display an error instead of a cached feed in the case that the fetch fails, by enabling the constant MAGPIE_CACHE_FRESH_ONLY: define(’MAGPIE_CACHE_FRESH_ONLY’, 1)
Check Tomcat Web Hosting services for best quality webspace to host your web application.

484 CHAPTER 20 WEB SERVICES Figure 20-3.

Sunday, November 25th, 2007

484 CHAPTER 20 WEB SERVICES Figure 20-3. Aggregating feeds Although the use of a static array for containing feeds certainly works, it might be more practical to maintain them within a database table, or at the very least a text file. It really all depends upon the number of feeds you ll be using, and how often you intend on managing the feeds themselves. Limiting the Number of Displayed Headlines Some Web site developers are so keen on RSS that they wind up dumping quite a bit of information into their published feeds. However, you might be interested in viewing only the most recent items, and ignoring the rest. Because Magpie relies heavily on standard PHP language features such as arrays and objects for managing RSS data, limiting the number of headlines is trivial, because you can call upon one of PHP s default array functions for the task. The function array_slice() should do the job quite nicely. For example, suppose you want to limit total headlines displayed for a given feed to three. You can use array_slice() to truncate it prior to iteration, like so: $rss->items = array_slice($rss->items, 0, 3); Revising the previous script to include this call results in output similar to that shown in Figure 20-4.
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

CHAPTER 20 WEB SERVICES Aggregating Feeds Of (Web hosting script)

Saturday, November 24th, 2007

CHAPTER 20 WEB SERVICES Aggregating Feeds Of course, chances are you re going to want to aggregate multiple feeds and devise some means for viewing them simultaneously. To do so, you can simply modify Listing 20-2, passing in an array of feeds. A bit of CSS may also be added to shrink the space required for output. Listing 20-3 shows the rendered version. Listing 20-3. Aggregating Multiple Feeds with Magpie channel[’title’]; echo “

$feedTitle
“; foreach ($rss->items as $item) { $link = $item[’link’]; $title = $item[’title’]; $description = isset($item[’description’]) ? $item[’description’]. “
” : “”; echo “$title
$description”; } echo “

“; } ?> Figure 20-3 depicts the output based on these three feeds.
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

482 CHAPTER 20 (Web site design) WEB SERVICES Listing 20-2.

Friday, November 23rd, 2007

482 CHAPTER 20 WEB SERVICES Listing 20-2. Rendering an RSS Feed with Magpie channel[’title’]; echo “Latest News from $feedTitle“; foreach ($rss->items as $item) { $link = $item[’link’]; $title = $item[’title’]; // Not all items necessarily have a description, so test for one. $description = isset($item[’description’]) ? $item[’description’] : “”; echo “

$title
$description

“; } ?> Note that Magpie does all of the hard work of parsing the RSS document, placing the data into easily referenced arrays. Figure 20-2 shows the fruits of this script. Figure 20-2. Rendering an RSS feed within the browser As you can see from Figure 20-2, each feed item is formatted with the title linking to the complete entry. So, for example, following the Ohio LinuxFest 2005 link will take the user to http://ablog.apress.com/?p=639#more-639.
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

CHAPTER 20 WEB (Make a web site) SERVICES [channel] => Array

Thursday, November 22nd, 2007

CHAPTER 20 WEB SERVICES [channel] => Array ( [title] => Jason Gilmore [link] => http://blogs.apress.com/ [tagline] => ) [textinput] => Array ( ) [image] => Array ( ) [feed_type] => RSS [feed_version] => 2.0 [encoding] => ISO-8859-1 [_source_encoding] => [ERROR] => [WARNING] => [_CONTENT_CONSTRUCTS] => Array ( [0] => content [1] => summary [2] => info [3] => title [4] => tagline [5] => copyright ) [_KNOWN_ENCODINGS] => Array ( [0] => UTF-8 [1] => US-ASCII [2] => ISO-8859-1 ) [stack] => Array ( ) [inchannel] => [initem] => [incontent] => [intextinput] => [inimage] => [current_field] => [current_namespace] => [last_modified] => Mon, 26 Sep 2005 19:43:48 GMT [etag] => “50e4-413-fa6a7a9f” ) Note the presence of the four object attributes in each element of the items array. While the summary and description attributes may seem redundant, this information is replicated because Magpie supports both RSS and an alternative syndication format known as Atom (http://www.intertwingly.net/wiki/pie/FrontPage), which uses the attribute Summary instead of Description. When retrieving RSS values using the Magpie methods, which are introduced soon, such redundancy will be neither apparent nor relevant. Following items is the channel array, which contains information pertinent to the feed in general, including the feed title, domain, and other attributes not shown in the example feed. Finally, information pertinent to the feed s technical aspects is offered, including the encoding type, date of last modification, and RSS version. Of course, for most users, only the information found in the itemsand channel arrays is of interest, so don t worry too much about the attributes that aren t particularly familiar. The following examples demonstrate how the data is peeled from this object and presented in various fashions. Retrieving an RSS Feed Based on your knowledge of Magpie s parsing behavior, rendering the feed components should be trivial. Listing 20-2 demonstrates how easy it is to render a retrieved feed within a standard browser.
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.

480 CHAPTER 20 WEB SERVICES This returns (Web design tools)

Wednesday, November 21st, 2007

480 CHAPTER 20 WEB SERVICES This returns the following output (containing only one item, for readability): MagpieRSS Object ( [parser] => Resource id #9 [current_item] => Array ( ) [items] => Array ( [0] => Array ( [title] => Ohio LinuxFest 2005 [link] => http://blogs.apress.com/?p=639#more-639 The annual Ohio LinuxFest 2005 conference is rapidly approaching, taking place at the Columbus Convention Center on October 1, 2005… [summary] => The annual Ohio LinuxFest 2005 conference is rapidly approaching, taking place at the Columbus Convention Center on October 1, 2005… ) [1] => Array ( [title] => Retrieving Map Location Coordinates [link] => http://blogs.apress.com/?p=634#more-634 [description] => In the first installment of a three-part series for Developer.com, you learned how to take advantage of Google’s amazing mapping API… [summary] => In the first installment of a three-part series for Developer.com, you learned how to take advantage of Google’s amazing mapping API… ) [2] => Array ( [title] => Pro PHP Security Published [link] => http://blogs.apress.com/?p=626#more-626 [description] => The Web’s greatest advantage, accessibility, has also proved to be its greatest detriment in terms of security… [summary] => The Web’s greatest advantage, accessibility, has also proved to be its greatest detriment in terms of security… ) )
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

CHAPTER 20 WEB SERVICES MagpieRSS MagpieRSS (Magpie (Web server on xp)

Tuesday, November 20th, 2007

CHAPTER 20 WEB SERVICES MagpieRSS MagpieRSS (Magpie for short) is a powerful RSS parser written in PHP by Kellan Elliott-McCrea. It s freely available for download via http://magpierss.sourceforge.net/ and is distributed under the GPL license. Magpie offers developers an amazingly practical and easy means for retrieving and rendering RSS feeds, as you ll soon see. In addition, Magpie offers users a number of cool features, including: Simplicity: Magpie gets the job done with a minimum of effort by the developer. For example, typing a few lines of code is all it takes to begin retrieving, parsing, and converting RSS feeds into an easily readable format. Nonvalidating: If the feed is well formed, Magpie will successfully parse it. This means that it supports all tag sets found within the various RSS versions, as well as your own custom tags. Bandwidth-friendly: By default, Magpie caches feed contents for 60 minutes, cutting down on use of unnecessary bandwidth. You re free to modify the default to fit caching preferences on a per-feed basis (which is demonstrated later). If retrieval is requested after the cache has expired, Magpie will retrieve the feed only if it has been changed (by checking the Last-modified and ETag headers provided by the Web server). In addition, Magpie recognizes HTTP s GZIP content-negotiation ability when supported. Installing Magpie Like most PHP classes, installing Magpie is as simple as placing the relevant files within a directory that can later be referenced from a PHP script. The instructions for doing so follow: 1. Download Magpie from http://magpierss.sourceforge.net/. 2. Extract the package contents to a location convenient for inclusion from a PHP script. For instance, consider placing third-party classes within an aptly named directory located within the PHP_INSTALL_DIR/includes/ directory. Note that you can forego the hassle of typing out the complete path to the Magpie directory by adding its location to the include_path directive found in the php.ini file. 3. Include the Magpie class (rss_fetch.inc) within your script: require(’magpie/rssfetch.php’); That s it! You re ready to begin using Magpie. How Magpie Parses a Feed Magpie parses a feed by placing it into an object consisting of four fields: channel, image, items, and textinput. In turn, channel is an array of associative arrays, while the remaining three are associative arrays. The following script retrieves the blog.xml feed, outputting it using the print_r() statement:
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.