Hello everyone. I got this script that sends XML data to United Parcel
Service (UPS) to receive rates.
XML data is sent to the server, and a response is sent back also in XML.

The problem is the parser, the data gets fed into it by url only, and I
would like to feed data to it via a variable that is filled by the curl
process of sending / receiving the XML.

Here is the parser and how I retrieve the data from it:

function startElement($parser, $name, $attrs=''){
  global $ary_path;
  array_push($ary_path, $name);

function endElement($parser, $name, $attrs=''){
  global $ary_path;

function characterData($parser, $data){
  global $ary_parsed_file, $ary_path, $int_starting_level;
  $str_trimmed_data = trim($data);
  if (!empty($str_trimmed_data)) {
    $str_array_define = '$ary_parsed_file';
      for ($i = $int_starting_level; $i < count($ary_path); $i++) {
        $str_array_define .= '[\'' . $ary_path[$i] . '\']';
      $str_array_define .= " = '" . $str_trimmed_data . "';";
      // DEBUG
      //echo "\n" . $str_array_define;
  } // if

$ary_path = array();
$ary_parsed_file = array();
$int_starting_level = 1;

$xml_file =

$type = 'UTF-8';

$xml_parser = xml_parser_create($type);
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
xml_set_element_handler($xml_parser, 'startElement','endElement');
xml_set_character_data_handler($xml_parser, 'characterData');

if (!($fp = fopen($xml_file, 'r'))) {
   die("Could not open $xml_file for parsing!\n");

while ($data = fread($fp, 1024000)) {
   if (!($data = utf8_encode($data))) {
       echo 'ERROR'."\n";
   if (!xml_parse($xml_parser, $data, feof($fp))) {
       die(sprintf( "XML error: %s at line %d\n\n",


#///// This loads up retrieves values into sessions for use in the
shopping cart.

The file this script is connecting to (rates.php) is the actual script
and curl process that sends / receives the XML data to and from ups's
servers. The above code is just the parser.

Thank you in advance for any help.

-Wendell Frohwein

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to