[UPHPU] How to create an XML file

Nathan Lane nathamberlane at gmail.com
Fri Feb 29 13:37:40 MST 2008


Inline in my web page I have the following:

$map_container_width = 50;
$map_container_height = 50;
$dom = new DOMDocument('1.0', 'utf-8');

$root = $dom->createElement('div');
$root->setAttribute('id', 'mapContainer');
$root->setAttribute('class', 'mapContainer');

$dom->appendChild($root);

for($i = 0; $i < $map_container_width; $i += 1) {
    for($j=0; $j < $map_container_height; $j += 1) {
        $tileId = 'tile-' . $i . ',' . $j;
        $newTile = $dom->createElement('div');
        $newTile->setAttribute('id', $tileId);
        //echo 'hello ' . $tileId;
        $newTile->setAttribute('class', 'laidTile');

        $root->appendChild($newTile);
    }
}

echo $dom->saveXML();

So my problem is that instead of appending each of the new elements after
each other, this is nesting the new elements inside of each other - anybody
know why? I can't figure it out.

Please help,

-- 
Nathan Lane
Home, http://nathandelane.awardspace.com


More information about the UPHPU mailing list