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!