Reading sub-elements using XML Reader

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am reading the following xml data in a very large file using XML reader, the xml structure looks like the xample given below

<item>
    <engine>head</engine>
    <brake>tail</brake>
    <tires>head</tires>
        <chromes>part head 1</chromes>
        <chromes>Part head 2</chromes>
    <seats>tail</seats>
</item>
<item>
    <engine>head</engine>
    <brake>tail</brake>
    <tires>head</tires>
        <chromes>part head 1</chromes>
        <chromes>Part head 2</chromes>
    <seats>tail</seats>
</item>

I can read all elements apart from the sub elements under <tires> and am kind of looking for a way to read these sub elements.  I am using the code structure below

$reader = new XMLReader();
$reader->open($feedUrl);

while($reader->read())
{
    
    switch($reader->nodeType)
    {
        case(XMLREADER::ELEMENT):
        
        if($reader->localName == "engine")
        {
            echo $reader->value;
        }
        if($reader->localName == "brake")
        {
            echo $reader->value;
        }
        if($reader->localName == "tires")
        {
            echo $reader->value;
            //I FIGURE OUT THAT I SHOULD BE ABLE TO READ THE SUB ELEMENTS HERE BUT TRYING TO FIGURE IT OUT
        }
    }
}


Any thoughts ?


Cheers
       
---------------------------------
Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel and lay it on us.

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux