I have an XML string like this:
<DATA>
<CHILD_DATA ATVAL="value1"/>
<CHILD_DATA />
</DATA>
The final output I want is:
<DATA>
<CHILD_DATA ATVAL="value1"/>
<CHILD_DATA ATVAL="value2"/>
</DATA>
My twig $t
is at <DATA>
. Now I want to add an attribute to the second <CHILD_DATA />
. The attribute is ATVAL="value2"
. I tried the following:
$t->last_child('CHILD_DATA')->set_att{"ATVAL","value2"};
This didn't work. What's wrong with this code? Is there another way to do this?