<?php

// create a string with a xml-document
$xmlStr = <<<EOS
<?xml version='1.0'?>
<root_node>
        <child_node1>
                child_node1 text-node
        </child_node1>
        <child_node2 testAttr="attrVal">
                child_node2 text-node
        </child_node2>
        <child_node3>
                <childs_child_node>
                        childs_child_node text-node1
                </childs_child_node>
                <childs_child_node>
                        childs_child_node text-node2
                </childs_child_node>
        </child_node3>
</root_node>
EOS;

// create SimpleXml-Object with the string
$xmlObj = simplexml_load_string($xmlStr);
//~ var_dump($xmlObj); // dumps the structure


//
// Accessing the Text-Nodes
//

// The first and the second Text-Nodes
// could directly accessed by their Parent-Node-Names
echo $xmlObj->child_node1; // output: child_node1 text-node
echo $xmlObj->child_node2; // output: child_node2 text-node

// The third and fourth Text-Nodes
// could accessed through an array that exists for the
// childs_child_node's
echo $xmlObj->child_node3->childs_child_node[0]; // output: childs_child_node text-node1
echo $xmlObj->child_node3->childs_child_node[1]; // output: childs_child_node text-node2


//
// Accessing the Attribute-Nodes
//

// The Attributes-Hash/Array could accessed through the attributes-Method
// of the SimpleXmlElements
$attr = $xmlObj->child_node2->attributes();
echo $attr['testAttr']; // output: attrVal


//
// Changing Text-Nodes
//
$xmlObj->child_node1 = 'new child_node1 text-node';


//
// Get the modified xml
//
echo $xmlObj->asXml();
/*
output:
<?xml version="1.0"?>
<root_node>
        <child_node1>new child_node1 text-node</child_node1>
        <child_node2 testAttr="attrVal">
                child_node2 text-node
        </child_node2>
        <child_node3>
                <childs_child_node>
                        childs_child_node text-node1
                </childs_child_node>
                <childs_child_node>
                        childs_child_node text-node2
                </childs_child_node>
        </child_node3>
</root_node>
*/


?>