0

I have a large XML file I am retrieving data from however I have several instances were the child elements are the same name and the XML reader stores the last one it come across:

<VehicleRemarketingBoat>
<MakeString>
Rodman Sportfisher
</MakeString>
</<VehicleRemarketingBoat>

<VehicleRemarketingEngine>
<MakeString>
Volvo
</MakeString>
</VehicleRemarketingEngine>

I would like to Detect the parent tag so I can then collect the data from the child tag.

THIS ISSUE IS SOLVED CODE UPDATED TO FIXED VERSION:

if($xml->nodeType == XMLReader::ELEMENT && $xml->localName ==  'VehicleRemarketingBoat'){
         $node = simplexml_import_dom($doc->importNode($xml->expand(), true));
         $content['MakeString'] = $node->MakeString;

    }
if($xml->nodeType == XMLReader::ELEMENT && $xml->localName ==  'VehicleRemarketingEngine'){
         $node = simplexml_import_dom($doc->importNode($xml->expand(), true));
         $content['EngineMake'] = $node->MakeString;
         $PreOwnedData[] = $content;
         var_dump($PreOwnedData);
    }
  • Could you provide some information about the error you get? – markusschmitz Sep 29 '15 at 17:52
  • Well the error basically tells me that the array is empty when I attempt a Var_dump. Also when I do an Sql Insert it is empty. This first chunk of code does have information in it when I do a var_dump – Adam Khoury Design Sep 29 '15 at 20:18
  • Your question misses to much information to answer it. For a more generic approach see this answer: http://stackoverflow.com/questions/32668794/php-foreach-while-handling-chunks/32668941#32668941 You don't need to do all parsing with XMLReader, just the "records". After that expand the record into DOM and use Xpath. – ThW Sep 30 '15 at 09:46
  • Ok I managed to fix the problem I was having by mixing simpleXML in to the if statements, thanks for the link to the question that plus this questions [How to use XMLReader in PHP?](http://stackoverflow.com/questions/1835177/how-to-use-xmlreader-in-php) – Adam Khoury Design Sep 30 '15 at 14:17

0 Answers0