Home arrow PHP arrow Searching and Replacing Nodes with SimpleXML in PHP 5

Searching and Replacing Nodes with SimpleXML in PHP 5

Want to learn how to get the most out of the “simpleXML” extension that comes bundled with PHP 5? Welcome to the last part of the series “Working with simpleXML in PHP 5.” In three tutorials, this series covers topics ranging from the basics of parsing XML files with this library, to performing advanced tasks, such as searching, extracting and replacing nodes, and interoperating with the XML DOM.

TABLE OF CONTENTS:
  1. Searching and Replacing Nodes with SimpleXML in PHP 5
  2. Going deeper into parsing XML strings: comparing nodes
  3. Finding nodes inside a XML string: using the “Xpath()” method
  4. Replacing nodes within a XML string: using the “asXML()” method
  5. Using a few additional methods: finding child nodes, accessing attributes and using the XML DOM
By: Alejandro Gervasio
Rating: starstarstarstarstar / 11
June 26, 2006

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Introduction

Quite possibly, if you’ve read the two preceding articles of this series, you’ll know how to load XML files and strings onto PHP objects by using the helpful “simplexml_load_file()” and “simplexml_load_string()” functions. You'll also know how to access parent and child XML nodes through a simple array syntax.

Also, at this point you’ll realize that one of the best things about this extension is how easily you can use it for parsing XML data by using typical foreach loops, which makes all the XML processing operations a breeze. Here, there’s no need to deal with complex parsers. Once XML data has been stored in a PHP object, the process for accessing nodes is reduced to navigating the corresponding tree and calling the appropriate methods.

So far, the couple of functions that I mentioned before actually do a good job of  parsing simple XML files and strings. However, the “simpleXML” library has a few additional handy functions that I’d like to show you in this last tutorial. That said, in the next few lines, I’ll be covering these functions, in order to demonstrate how to quickly search and replace nodes within XML data strings.

So that’s the subject of this article. It’s time to continue learning about the “simpleXML” extension. Let’s do it together!



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

blog comments powered by Disqus
   

PHP ARTICLES

- 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...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap

Dev Shed Tutorial Topics: