There are a number of ways to parse, create and save XML in PHP. Two of the more common methods used are the SimpleXML library, and the DOMDocument class.

SimpleXML is extremely, well... Simple. With SimpleXML we can parse an XML document and easily process its elements, attributes, children and values.

Consider the following well formed, valid XML document.


<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE note
[
<!ELEMENT book (title,author,genre,year,pages)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT genre (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT pages (#PCDATA)>
<!ATTLIST year era CDATA "AD">
<!ENTITY unknown "Unknown">
]>

<books>
<book>
	<title>A Christmas Carol</title>
	<author>Charles Dickens</author>
	<genre>Fiction</genre>
	<year era="AD">1843</year>
	<pages>86</pages>
	<link><![CDATA[http://linktobook?link=1&data=2 ]]></link>
</book>	

<book>
	<title>A Treatise on Government</title>
	<author>Aristotle</author>
	<genre>Non-Fiction</genre>
	<year era="BC">322</year>
	<pages>195</pages>
	<link><![CDATA[http://linktobook?link=2&data=3 ]]></link>
</book>	

<book>
	<title>A Thief in the Night</title>
	<author>E. W. Hornung</author>
	<genre>Short Stories</genre>
	<year era="AD">1905</year>
	<pages>182</pages>
	<link><![CDATA[http://linktobook?link=3&data=4 ]]></link>
</book>	

<book>
	<title>Some Book</title>
	<author>&unknown;</author>
	<genre>Non-Fiction</genre>
	<year era="BC">500</year>
	<pages>1000</pages>
	<link><![CDATA[http://linktobook?link=4&data=5 ]]></link>
</book>	
</books>

Parsing this document is as simple as creating a SimpleXML object with the file as a parameter, and looping through it's elements with a foreach loop.

$simple_xml = simplexml_load_file('valid.xml');
foreach($simple_xml as $book){
    echo "Title: " . $book->title;
    echo "Author: " . $book->author;
    echo "Genre: " . $book->author;
    echo "Year: " . $book->year;
    // Get the Attribute
    echo "Era: " . $book->year->attributes()->era;
    echo "Pages: " . $book->pages;
    echo "Link: " . $book->link;
    echo "************************;
}

Note that SimpleXML objects can also be created the Object Oriented way by instantiating an object and passing the XML file path into it's contructor:

$simple_xml = new SimpleXMLElement('valid.xml', NULL, true);

As we loop through each book element, we can access its child elements by name. We can also access a child element's attributes by name, in this example, we access the 'era' attribute of the 'year' child element.
For more information on XML elements, attributes and entities, read
XML Fundamentals: Elements, Attributes and Entities

SimpleXML is great for quick and easy parsing, but what if our parsing needs are a bit more complex. Let's say for example that we were parsing XML from a web service and did not know the names of the child elements. Let's also say that we need to add a child element as we parse it's parent. We can accomplish both of these tasks using DomDocument.

The DomDocument is a robust class that allows us to add, modify, and even search for elements (XPATH queries).

$dom_xml = new DOMDocument();
$dom_xml->load('valid.xml');
$books = $dom_xml->getElementsByTagName('book');
foreach($books as $book){
	//add new element
	$date = $dom_xml->createElement("time-stamp");
	$date->appendChild($dom_xml->createTextNode(time()));
	$book->appendChild($date);
	foreach($book->childNodes as $node){
		if($node->nodeName != '#text') //omit blank space
		echo $node->nodeName . ": " . 
                $node->nodeValue;
	}
	echo "************************";
}	

In this example, we obtain a collection of 'book' elements and loop through them. As we loop through each element we create a new element called $date, append a text node to it (the date), and then append the $date element to the parent $book. Next, we abstractly loop through each child of the current 'book' element and output the child's node-name and value.

There is much more that can be done with DOM parsing. For more information check out the PHP online manual's entry on DOM here.
W3 Schools also has a great collection of tutorials and information.