1

I've tried many pre built parsers including the xml2array parser with no luck. I've also tried my own without any success either. I've tried simplexmlelement/xpath and a bunch of different ways with the same result so I'm at a place where I'm banging my head on my keyboard.

Basically I'm trying to parse code the API call is spitting back to me. I'm making a soap call and getting the xml content via curl (https).

Here is an example of the xml I'm getting back: HTTP/1.1 100 Continue

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Powered-By: Servlet 2.5; JBoss-5.0/JBossWeb-2.1
Content-Type: text/xml;charset=UTF-8
Transfer-Encoding: chunked
Date: Sat, 21 Apr 2012 19:49:30 GMT


<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
    <env:Header></env:Header>
    <env:Body>
        <ns:processRequestResponse xmlns:ns='hidden.address'>
            <result>
                <?xml version="1.0" encoding="UTF-8"?>
                    <CRMMessage language="en_US" currency="USD" isTrustedSAT="false" hostversion="hiddenINT">
                        <RequestCode>HiddenMethoForCall</RequestCode>
                        <ResponseCode>A</ResponseCode>
                        <ResultSet>
                            <ResultSetMetaData>
                                <RSColumn name="FirstName" type="string" nullable="true"></RSColumn>
                                <RSColumn name="LastName" type="string" nullable="true"></RSColumn>
                                <RSColumn name="EmailAddress" type="string" nullable="true"></RSColumn>
                            </ResultSetMetaData>
                            <Rows>
                                <Row id="hiddenINT">
                                    <Col>John</Col>
                                    <Col>Doe</Col>
                                    <Col>john@doe.com</Col>
                                </Row>
                            </Rows>
                        </ResultSet>
                    </CRMMessage>

            </result>
        </ns:processRequestResponse>
    </env:Body>
</env:Envelope>

I tried using xml2array, but that explicitly states that it doesn't support parsing same name keys in the same level.

I'm not sure if it will matter, as I'm open to any parsers suggested, but here is one that I put together (this is inside the class that handles the request after the request is made):

$retVal = curl_exec($soap_do);  

if($retVal === false) {
    $err = 'Curl error: ' . curl_error($soap_do);  
    throw new requestManager($err);
} else {
    $string = strstr($retVal, '<');
        // $aResp = simplexml_load_string($string);


    if(!function_exists('xml_parser_create')) { 
        //print "'xml_parser_create()' function not found!"; 
        return array(); 
    } 
    curl_close($soap_do);

    //custom parse
    $aResp = array();
    $i=0;
    $parser = xml_parser_create();
    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
    // xml_parse_into_struct($parser, $string, $values, $tags);
    xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
    xml_parse_into_struct($parser, trim($string), $values); 
    xml_parser_free($parser);
    // var_dump($values);
    foreach($values as $val) {
        foreach($val as $key=>$value) {
            if($key=='value'){
                if(is_array($value)) {
                    foreach($value as $k=>$v) {
                        echo $v;
                        $value[$i]=$value;
                    }
                }else {
                    $aResp[$i]=$value;
                    echo '<h1>'.$key.'</h1>';
                    echo '<h2>'.$value.'</h2><br>';
                }
                $i++;
            }

        }
    }
}

Any help would be appreciated as I'm hitting a wall here. I've checked every resource I can think of with no luck. Thank you!

Tedi
  • 11
  • 2
  • [According to @Ivan](http://stackoverflow.com/a/4195132/568785), PHP 5 has [a built-in SoapClient](http://php.net/manual/en/book.soap.php). Have you tried it? – Bailey Parker Apr 21 '12 at 20:09
  • Yes - without much luck. – Tedi Apr 21 '12 at 20:18
  • What errors have the built-in parsers given you? – Bailey Parker Apr 21 '12 at 20:21
  • Well, for one, the server I'm making the request from didn't have the SOAP module installed but I did it from a different machine where curl was successful. Granted I'm not as familiar with the php built in soap call as I am with curl, I was getting a few errors. The service I'm making the request to has a bunch of requirements - it needs a key to be associated with each request, the body of the request needs to be hashed, and a few other things. Although I may have been doing something wrong with the SOAP call the biggest issues I ran across were bad request responses. – Tedi Apr 21 '12 at 20:25
  • If it helps, the **xml_parse_into_struct($parser, trim($string), $values);** line is what's dumping everything into the array and I believe it's right there that the values are being merged because they have the same key name(s). – Tedi Apr 21 '12 at 22:15

0 Answers0