how can i add the sibling when i generate the code with for loop
<root>
<Book>
<type serial_no="1" name="little monkey"/>
<type serial_no="2" name="little monkey"/>
</Book>
<CD>
<type serial_no="1" name="ABC song"/>
<type serial_no="2" name="ABC song"/>
</CD>
</root>
My code is as follow
$xml = new SimpleXMLElement('<root/>');
for ($i = 1; $i <= 2; ++$i) {
$stock = $xml->addChild('Book');
$stock ->addChild('Type', 'serial_no="'.$i.'name="little monkey"');
$stock = $xml->addChild('CD');
$stock ->addChild('Type', 'serial_no="'.$i.'name="ABC song"');
}
Header('Content-type: text/xml');
print($xml->asXML());
I know there are something wrong with my code Please give me some suggestion
No comments:
Post a Comment