PHP Classes

How to parse more than one file

Recommend this page to a friend!

      simple XML  >  All threads  >  How to parse more than one file  >  (Un) Subscribe thread alerts  
Subject:How to parse more than one file
Summary:Problems with processing several files
Messages:2
Author:Markus Möller
Date:2007-09-11 09:08:30
Update:2010-06-22 20:10:04
 

 


  1. How to parse more than one file   Reply   Report abuse  
Picture of Markus Möller Markus Möller - 2007-09-11 09:08:30
Hi all,

I tried to parse two files one after another. The first attempt was to copy all lines like this:

$xml_file="demo1.xml";
$xml=new XML();
$xml->file_read($xml_file);
$xml->parse();
$xml->debug();

$xml_file="demo2.xml";
$xml=new XML();
$xml->file_read($xml_file);
$xml->parse();
$xml->debug();


Unfortunately this results in several error-messages like this:
Warning: xml_parse(): Unable to call handler tag_data() in myTopSecretDir/XML.class.php on line 53

Warning: xml_parse(): Unable to call handler tag_open() in myTopsecretDir/XML.class.php on line 53



After this I tried to reuse the XML instance:

$xml_file="demo1.xml";
$xml=new XML();
$xml->file_read($xml_file);
$xml->parse();
$xml->debug();

$xml_file="demo2.xml";
$xml->file_read($xml_file);
$xml->parse();
$xml->debug();


Bad idea! Now there are less warnings:
Warning: xml_parse(): 366 is not a valid XML Parser resource in myTopsecretDir/XML.class.php on line 53

Warning: xml_parser_free(): 366 is not a valid XML Parser resource in myTopsecretDir/XML.class.php on line 54


But the new XML file isn't processed correctly. Instead of reading the demo2.xml the content of $xml is unchanged and returns the old values from demo1.xml as $xml->debug() shows.


So have anybody experience (and maybe solutions) for prcessing several files?

Thanks and best regard!
markus

  2. Re: How to parse more than one file   Reply   Report abuse  
Picture of Oliver Strecke Oliver Strecke - 2010-06-22 20:10:04 - In reply to message 1 from Markus Möller
1. seperate instances

$xml1_file="demo1.xml";
$xml1=new XML();
$xml1->file_read($xml_file);
$xml1->parse();
$xml1->debug();

$xml2_file="demo2.xml";
$xml2=new XML();
$xml2->file_read($xml_file);
$xml2->parse();
$xml2->debug();


or 2. unset and reuse the variable

$xml_file="demo1.xml";
$xml=new XML();
$xml->file_read($xml_file);
$xml->parse();
$xml->debug();

unset($xml);

$xml_file="demo2.xml";
$xml=new XML();
$xml->file_read($xml_file);
$xml->parse();
$xml->debug();