
 Torsten Singleboerse-Tipp - 2013-05-01 21:42:34
Hi,
i have a xml, in that some tags ar not at all products.
<products>
 <product>
  <name>pr1</name>
  <ean>1234</ean>
  <description>this is one product</description>
 </product>
 <product>
  <name>pr2</name>
  <description>this is one product</description>
 </product>
 <product>
  <name>pr3</name>
  <ean>12334</ean>
  <description>this is one product</description>
 </product>
</products>
How to read this file? (The file is very big, about 230MB)
Here is the code i use:
    require('xml_parser.php');
    $file_name = 'otto_roh.xml';
    $error = XMLParseFile($parser, $file_name, 1, $file_name.'.cache');
    if(strlen($error) == 0)
    {
        /*
         * The types array defines the types and structure of the document
         * to be validated before extracting its data values.
         */ 
        $content_types = array(
            'products'=>array(
                'type'=>'hash',
                'types'=>array(
                    'product'=>array(
                        'type'=>'hash',
                        /* allow tag to appear an unlimited number of times */
                        'maximum'=>'*',
                        'types'=>array(
                            'name'=>array(
                                /* The default maximum and minimum times is 1 for required tags */
                                'type'=>'text',
                            ),
                            'ean'=>array(
                                'type'=>'text',
                            ),
                            'description'=>array(
                                'type'=>'text',
                            ),
                        )
                    )
                )
            )
        );
And where i can make the sql statements to write the data from the xml to my database? I cannot read the whole xml file at once, because it is 230MB.
Best regards
Torsten