25.09.2014 Views

ZEND PHP 5 Certification STUDY GUIDE

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

196 ” XML and Web Services<br />

i<br />

If a file with the same path already exists, a call to asXML() will overwrite it without<br />

warning (provided that the user account under which <strong>PHP</strong> is running has the proper<br />

permissions).<br />

While SimpleXML provides the functionality for adding children and attributes, it<br />

does not provide the means to remove them. It is possible to remove child elements,<br />

though, using the following method.<br />

$library->book[0] = NULL;<br />

This only removes child elements and their attributes, however. It will not remove<br />

attributes from the element at the book level. Thus, the isbn attribute remains. You<br />

may set this attribute to NULL, but doing will only cause it to become empty and will<br />

not actually remove it. To effectively remove children and attributes, you must export<br />

your SimpleXMLElement to DOM (explained later in this chapter), where this more<br />

powerful functionality is possible.<br />

Working With Namespaces<br />

The use of XML namespaces allows a provider to associate certain element and attribute<br />

names with namespaces identified by URIs. This qualifies the elements and<br />

attributes, avoiding any potential naming conflicts when two elements of the same<br />

name exist yet contain different types of data.<br />

The library.xml document used thus far does not contain any namespaces, but<br />

suppose it did. For the purpose of example, it might look something like this:<br />

<br />

<br />

<br />

Fahrenheit 451<br />

Ray Bradbury<br />

Del Rey<br />

<br />

<br />

Licensed to 482634 - Amber Barrow (itsadmin@deakin.edu.au)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!