Home arrow PHP arrow Inserting Comments and Accessing Nodes with the DOM XML Extension in PHP 5

Inserting Comments and Accessing Nodes with the DOM XML Extension in PHP 5

Welcome to the third chapter of the series “A quick overview of the DOM XML extension in PHP 5.” As the article’s title suggests, this series walks you through using the most relevant methods that come packaged with this powerful XML-related PHP extension to perform specific operations on XML documents by using the API of the Document Object Model.

  1. Inserting Comments and Accessing Nodes with the DOM XML Extension in PHP 5
  2. Reviewing how to insert attributes and CDATA nodes with the DOM XML library
  3. Appending comment nodes to a given XML document
  4. Accessing XML nodes by their ID attribute
By: Alejandro Gervasio
Rating: starstarstarstarstar / 3
March 11, 2008

print this article



When it comes to working with XML documents, PHP really shines. It provides web developers with a bunch of thorough extensions aimed at facilitating the manipulation of XML data in all sorts of clever ways. This includes the always popular “simpleXML” library and one that actually is the primary subject of this series of articles. In this case, I’m talking about the DOM XML extension, which allows you to handle XML documents by using the DOM API. Thus, if you’re interested in learning how to put this extension to work for you quickly, look no further, because you’ve come to the right place.

Now that I've introduced you to the main subject of this series, I think it’s time to rehash some of the most relevant topics that were treated in the preceding article of the series. Well, as you’ll possibly recall, in the last tutorial I explained how to utilize the “createAttribute()” and “createCDATASection()” methods, which are bundled with the DOM XML extension, to insert attributes and CDATA nodes into an existing XML document.

Since these methods offer an easy learning curve, I assume that you shouldn’t have major difficulties understanding how they can be used to aggregate certain attributes and create CDATA sections within a string of XML data.

The DOM XML library has many other useful methods, aside from the ones I've already mentioned, which can be utilized to insert different types of nodes into a given XML document. What’s more, the extension allows you to access specific elements within the document tree by using their corresponding ID attributes. Therefore, in this third installment of the series, I’ll be teaching you specifically how to append comment nodes to a given XML string and how to extract certain elements via their IDs.

Having already outlined the subject of this tutorial, let’s learn how to perform the aforementioned tasks with the API provided by the DOM XML extension. Let’s get going!

>>> 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: