BIG problem.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Bedford

    #1

    BIG problem.

    I've to manage quite very large XML files. I tough it was an SQL error, but
    I've figured out the problem is somewhere else.

    I've a big structure, with lot of datas and pictures encoded in every XML
    files. Sometimes, I've error, and the script crashes.

    Here is the code:

    $xml_parser = xml_parser_crea te();
    xml_set_element _handler($xml_p arser, "startEleme nt", "endElement ");
    xml_set_charact er_data_handler ($xml_parser, "FDataHandler") ;

    while ($data = fread($fp, 4096)) {
    if (!xml_parse($xm l_parser, $data, feof($fp))) {
    die(sprintf("XM L error: %s at line %d",
    xml_error_strin g(xml_get_error _code($xml_pars er)),
    xml_get_current _line_number($x ml_parser)));
    rename($XMLPath .$file, $XMLPath.$failp ath.$file); //move file in error
    path
    $OK = false;
    }
    }
    fclose($fp);
    xml_parser_free ($xml_parser);

    Now, this part of the code takes 4096 bytes and parse datas:
    <datastart>
    <data1>20040101 </data1>
    <data2>20040220 </data2>
    <data3>20040810 </data3>
    </datastart>

    Now, if the 4096 bytes are in the middle of the file, I get big problems. In
    my case, the data2 is cutted somewhere in the middle
    The script should only work when the </datastart> is reached, isn'it ??? but
    how to do so ? The actual file is 5MB large, with lot of pictures in it.

    Bob


  • Alvaro G Vicario

    #2
    Re: BIG problem.

    *** Bob Bedford wrote/escribió (Mon, 17 Jan 2005 18:05:43 +0100):[color=blue]
    > while ($data = fread($fp, 4096)) {[/color]
    ^^^^
    [color=blue]
    > Now, if the 4096 bytes are in the middle of the file, I get big problems.[/color]

    Does you XML parser consider the case where elements are larger than 4096
    bytes?



    --
    -- Álvaro G. Vicario - Burgos, Spain
    -- Thank you for not e-mailing me your questions
    --

    Comment

    • Bob Bedford

      #3
      Re: BIG problem.

      "Alvaro G Vicario" <alvaro_QUITAR_ REMOVE@telecomp uteronline.com> a écrit
      dans le message de news: 1jpjgjum4qvs2$. 1ki2npp3js5nv.d lg@40tude.net.. .[color=blue]
      > *** Bob Bedford wrote/escribió (Mon, 17 Jan 2005 18:05:43 +0100):[color=green]
      >> while ($data = fread($fp, 4096)) {[/color]
      > ^^^^
      >[color=green]
      >> Now, if the 4096 bytes are in the middle of the file, I get big problems.[/color]
      >
      > Does you XML parser consider the case where elements are larger than 4096
      > bytes?[/color]

      Actually not, because I don't know how to do so.
      I do have this:

      function endElement($par ser, $name)
      {
      switch($name){
      case 'datastart': //commencer à enregistrer les données importantes pour
      les véhicules
      //save in DB. Get the error here sometimes
      I didn't manage to check if the elements were larger than 4096 as I tough
      the save in DB code was only executed when the closing tag was reached. If
      I'm wrong, what's the solution ?

      Bob

      Comment

      Working...