tags:

views:

88

answers:

2

I love SimpleXMLElement-- it's great as a XML Element Parser.So I am thinking is there an XML writer-- the one that changes the attribute values, for example, changing

<?xml version="1.0"?>
<a b="One Two">
    <c>Three Four</c>
    <d>Five Six</d>
</a>

to

<?xml version="1.0"?>
<a b="One Two">
    <c>seven</c>
    <d>eight</d>
</a>

Is there any existing library that does that? SimpleXMLElement doesn't provide that, I afraid.

Note that I am reading the XML from a file, not from a string.

A: 

Keith Devens' PHP XML Library, version 1.2b

http://keithdevens.com/software/phpxml

It allows you to easily parse XML into a PHP data structure, and it allows you to serialize PHP data structures into XML.

Robert Harvey
+2  A: 
$xml = '<?xml version="1.0"?>
<a b="One Two">
  <c>Three Four</c>
  <d>Five Six</d>
</a>';

$xml = simplexml_load_string($xml);
$xml->c = 'seven';
$xml->d = 'eight';

echo $xml->asXML();

Works!

Evert