I've got a simple Soap request that collects some information from a remote server:

<?php
        $cunum=$_GET[cunum];

    $client = new
            SoapClient(
                  "http://xxx/cfa-3.0.6/CFAManager?wsdl"
            );

    print $client->getCfaInfoByAccount($cunum, APTIS, jsmith);
?>

This works fine, and I get the raw data I want. It is returned in the following format:

<xml><errorCode>0000</errorCode><errorMessage>Transaction Completed Successfully!</errorMessage><responseTime>1</responseTime><rowsReturned>2</rowsReturned><cfaInfo>... </xml>

My question is:

What is the most straightforward way to convert this response into something that is readable for a web user? There are (literally) dozens of tutorials out there, but nothing sufficiently on point.

all help/thoughts appreciated.

    Hm.. I woul dhave a look at the XML parsing functions in the manual, and search for parse xml php. That should get you loads of tutorials.

    You mention that there are no clear tutorials out there.. That might just mean you have to dig a little deeper 😃

    I do not have a lot of experience parsing xml, so I unfortunately cannot give you a more detailed answer

      Thanks. I've burned more than a few hours doing exactly what you suggested (xml_parse, nuSOAP, etc. etc. etc. etc.).

      Again, although many, many kind people have shared knowledge with their specific cicurmstance on how to make their xml output something presentable, nothing out there matches the simple criteria I have and/or works sufficiently.

      The only thing that (I think) does is using regular expressions, which will be EXTREMELY time-consuming (I'm getting back 30-40 pieces of data in the response), so I'm asking if anyone around here has experience and/or a simple, straight-forward solution for parsing out SOAP responses in the format i noted.

      Thanks!

        As a very very simple method... (i've used this before to make it a bit easier to read)

        $newxml = str_replace("><", "><br/><", $xml);

        basically just splits all the tags onto new lines...

        You could always strip out whats between the < and > so you only have the contents and not the XML tags...

        It depends how nice you want it to look

          odd... I found a almost perfectly functioning parser in the manual when I looked there:

          <?php
          
          // http://uk.php.net/manual/en/function.xml-parser-create.php
          
          function ParseXml($data)
            {
            // create a new php xml parser
            $xml_parser = xml_parser_create();
          
            // PLaxce the XMl in a structure
            xml_parse_into_struct($xml_parser, $data, $vals, $index);
          
          
            //relese the parser
            xml_parser_free($xml_parser);
          
            // go parse now!
            $params = array();
            $level = array();
            $i=0;
            foreach ($vals as $xml_elem) {
          	if ($xml_elem['type'] == 'open') {
          	  if (array_key_exists('attributes',$xml_elem)) {
          		list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']);
          	  } else {
          		$level[$xml_elem['level']] = $xml_elem['tag'];
          	  }
          	}
          	if ($xml_elem['type'] == 'complete') {
          	  $start_level = 1;
          	  $php_stmt = '$params';
          	  while($start_level < $xml_elem['level']) {
          		$php_stmt .= '[$level['.$start_level.']]';
          		$start_level++;
          	  }
          	  $php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
          	  eval($php_stmt);
          	}
            }
            return $params;
          }
          ?>
          

          Not sure whether I modified the example

            Write a Reply...