Naamah Naamah - 1 year ago 90
PHP Question

How to change attribute on a simpleXML element?

I parsed a XML file with SimepleXML:

<element data="abc,def">

But now I want to append something to the "data" attribute. Not in the file, but in my variables (in the object structure that I got from simplexml_load_file).

How can I do that?

Answer Source

Untested, but should work:

$element->attributes()->data = ((string) $element->attributes()->data) . ',ghi';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download