tags:

views:

201

answers:

1

I have some PHP code to turn an XML file into a CSV file. During testing, I am not creating a CSV file, just echoing the results in a CSV format.

Whenever XMLReader reaches an empty element, it outputs all the attributes of the element.

1) Is there a way to output the attribute name with it's values i.e. (is there an $xml->AttributeName that goes with the $xml->value)?

2) Is there a way to sort for all attributes in the entire tree and not just those in the empty element?

<?php 

ini_set('memory_limit','50M');

$x = file_get_contents('H8_data.xml');

$xml = new XMLReader(); 
$xml->open('H8_data.xml', null, 1<<19); 

$num = 1;
while ($xml->read() && $num <= 2000) {
    if($xml->isEmptyElement) {
        if($xml->hasAttributes)  {
            while($xml->moveToNextAttribute()) { 
                echo $xml->value, ', '; 
            }
        }
    echo '<br />';
    $num++;
    }
}

?>