星期四, 12月 03, 2009

PHP XML Build


<?php
$doc = new DOMDocument('1.0', 'UTF-8');

$root = $doc->createElement('songs');
$doc->appendChild($root);

for($i=0;$i<10;$i++){

$root_child = $doc->createElement('song');
$root->appendChild($root_child);

$root_attr1 = $doc->createAttribute('url');
$root_child->appendChild($root_attr1);

$root_text = $doc->createTextNode('This is the root element!');
$root_attr1->appendChild($root_text);

$root_attr2= $doc->createAttribute('artist');
$root_child->appendChild($root_attr2);

$root_text = $doc->createTextNode('This is the root element!');
$root_attr2->appendChild($root_text);

$root_attr3 = $doc->createAttribute('track');
$root_child->appendChild($root_attr3);

$root_text = $doc->createTextNode('This is the root element!');
$root_attr3->appendChild($root_text);

}

print $doc->saveXML();
?>

沒有留言:

張貼留言

留個話吧:)

其他你感興趣的文章

Related Posts with Thumbnails