hi, I have a PHP script which sends a authorisation request to a Servlet and receives a response in XML format. I have also created a parser (using both DOM as well as SAX) for parsing the output.
My problem: The parser takes in input from an external xml file but the output from the servlet needs to be dynamically fed into the parser something like this: phpcomm.php <?php include_once ('xmlcommparser1.php'); --- --- --- $xmldata = $sysCurlReq->getSysCurlResp(); $appData = new XmlAppData ($xmldata); //print_r($appData->appArray) // display array contents ?> $xmldata contains the output which is sent directly to the parser [B]"xmlcommparser1.php"[/B] The xmlcommparser1.php is not working.. I am trying to convert the parser into form of a class with a function which receives $xmldata... I am pasting the parser code below if anyone wants a look.. wud appreciate a lot if anyone can figure out where I am going wrong! TIA, sandeep xmlcommparser1.php <?php class XmlAppData { var $appArray; var $xmlData; var $xml_parser; var $depth = array(); function XmlAppData($xmldata) { $this->xmlData = $xmldata; $this->xml_set_element_handler(); } //$file = "c:\apache\htdocs\a.xml"; function startElement($parser, $name, $attrs) { global $depth; for ($i = 0; $i < $depth[$parser]; $i++) { print " "; } // print "$name\n"; // print "$data"; $depth[$parser]++; } function endElement($parser, $name) { global $depth; $depth[$parser]--; } var $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); if (!($fp = fopen($file, "r"))) { die("could not open XML input"); } while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } print "$data"; } xml_parser_free($xml_parser); ?>