Forum Moderators: coopster

Message Too Old, No Replies

Add child to a child in XML with PHP5 DOM?

         

roxpace

7:38 pm on Apr 6, 2006 (gmt 0)

10+ Year Member



Does anyone know how to add a children node to a children in XML with PHP5 and DOM?

For example I have this structure:

<rootlevel>
<childlevel1>
<id>1</id>
<date>2006-01-01</date>
<names>
<name>
<id>10</id>
<firstname>John</firstname>
<lastname>Smith</lastname>
</name>
<name>
<id>11</id>
<firstname>Eva</firstname>
<lastname>Smith</lastname>
</name>
</names>
</childlevel1>
<childlevel1>
<id>2</id>
<date>2006-01-01</date>
<names>
<name>
<id>12</id>
<firstname>John</firstname>
<lastname>Doe</lastname>
</name>
<name>
<id>13</id>
<firstname>Eva</firstname>
<lastname>Doe</lastname>
</name>
</names>
</childlevel1>
</rootlevel>

And now I wanna add a name to the level rootlevel->childlevel1[id=2]->names, how do I do that?

And I ask the same question, how do I change data in a such field?

coopster

6:25 pm on Apr 8, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Why wouldn't you use the DOMNode Methods [php.net]?