HomePHP 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.
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!