Home arrow PHP arrow Working with Attributes and CDATA Sections with the DOM XML Extension

Working with Attributes and CDATA Sections with the DOM XML Extension

Undeniably, one of the most remarkable strengths of PHP is its robust set of extensions. They provide developers with the right tools to build a huge variety of web applications with minor hassles. And this characteristic is particularly evident when it comes to working with XML documents, since PHP comes packaged with a bunch of powerful libraries that allow it to handle XML data in all sorts of clever ways.

  1. Working with Attributes and CDATA Sections with the DOM XML Extension
  2. Reviewing some methods of the DOM XML extension
  3. Working with the createAttribute() method
  4. Inserting CDATA nodes into an XML document
By: Alejandro Gervasio
Rating: starstarstarstarstar / 3
March 04, 2008

print this article



A good example of this is the popular “SimpleXML” extension, which comes in handy when performing the most common operation required to work with XML documents -- using an approachable, easy-to-learn API. You might think that this library is the only one bundled with PHP that can be used to handle XML data, but this is completely erroneous.

There’s a PHP library that permits you to work with XML documents by using the DOM API. Does this name ring any bells for you? Yes, you’re right! Fortunately, PHP also provides programmers with the helpful DOM XML extension, which, as its name suggests, can be quite useful when processing XML documents via the Document Object Model.

Basically, this implies that you’ll be able to build XML documents from scratch, create and append new nodes, remove existing ones, work with custom attributes, etc., by using the methods offered by the DOM API, which include the popular “createElement(),” appendChild(),” and “getElementById().”

Of course, if you're used to working with JavaScript on a frequent basis, then the previous methods will be pretty familiar to you. But if you haven’t had the chance to develop client-side applications, you might want to read this article series to learn how to get started using the DOM XML extension bundled with PHP.

And speaking of the numerous features offered by this library, in the first article of the series I explained how to use some of its simplest methods to perform certain basic tasks on XML data, such as building new documents, creating elements and inserting nodes, and finally echoing the whole output to a browser.

However, this is merely a humble beginning, since the DOM XML library comes equipped with many other methods that can be useful for adding custom attributes to the existing nodes of a given XML document, and creating new CDATA sections, among other things. Therefore, assuming that all these topics are really interesting to you, in this second part of the series I’ll be discussing them in detail and logically accompanying the corresponding theoretical concepts with illustrative hands-on examples.

Does all this material sound good to you? Great! Let’s continue this journey now!

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: