PHP
  Home arrow PHP arrow Handling HTML Strings and Files with the DOM XML Extension in PHP 5
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Handling HTML Strings and Files with the DOM XML Extension in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 3
    2008-03-25


    Table of Contents:
  • Handling HTML Strings and Files with the DOM XML Extension in PHP 5
  • Loading HTML code from a specific string with the loadHTML() method
  • Reading contents from HTML files with the loadHTMLFile() method
  • Building HTML files from their DOM representation with the saveHTMLFile() method

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Handling HTML Strings and Files with the DOM XML Extension in PHP 5
    ( Page 1 of 4 )

    The DOM XML extension has a few additional methods that can be used to process HTML files and strings, at least at a pretty basic level. Thus, this fifth part of the series will be entirely focused on explaining how to work with these methods. I will include some illustrative code samples.

    Working on XML documents with PHP can be quite a challenging task, since this process often involves reading data from remote files, parsing specific nodes, inserting and removing elements from the document tree, and so forth. However, if you’re just about to tackle the development of a web application that requires thorough processing of XML data, there’s no need to start pulling your hair because PHP comes equipped with a helpful extension, called DOM XML, which can be used to parse XML documents in all sorts of clever ways using the API of the Document Object Model.

    Understanding how to use the methods and properties provided by this library requires a little effort from you, despite its fairly easy learning curve. Therefore, if you’re looking for a comprehensive guide on how to get the most out of this powerful XML-related PHP extension, then you should take a closer look at this article series. In doing so, you’ll hopefully learn a few useful things, such as creating XML documents from scratch, appending, copying, and removing nodes, and even processing HTML strings by way of their DOM representation. What else can you ask for?

    Now that you’re well aware of the topics that are treated in this series of articles, let me quickly review the items that were discussed in the last tutorial. This way you’ll be able to have clearer idea about how they can be linked with the ones I plan to cover in this article.

    Throughout the course of the preceding tutorial I explained how to access multiple nodes of a specific XML document using the “getElementsByTagName()” method, which presents practically the same functionality as the one utilized to parse web pages with JavaScript. In addition, I demonstrated how to read XML data from an existing text file via the “load()” method. And finally, I demonstrated how to read XML strings by way of a similar method, called “loadXML()”.

    As you can see, the DOM XML extension has plenty of options when it comes to moving portions of an XML document (or even the entire document) from one place to another. This is certainly a process that can be performed with minor hassles by utilizing the intuitive DOM API mentioned in the beginning.

    So far, so good. At this moment, I'm assuming that you’ve acquired a considerable background in performing some basic operations on simple XML documents through the functionality offered by the DOM XML extension. But what if I tell you that this library permits you to work with data formatted in plain HTML?

    Let’s not waste any more time in preliminaries and continue learning how to work with HTML and the DOM XML library. Let’s get started!



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek