Trim result from XML

I have this XML and I want to get the condition code to be returned so I can use it in my further programming. Wish that i can do if $ConditionCode=“EC202020” then…

I get all information where tag is opened and closed like msg, details and so on, but need help extract this code so I can use it in cach excpetation.

<response>
    <result code="1919">
      <msg>Invalid information</msg>
    </result>
    
    <extension>
      <conditions>
       
        <condition code="EC101010" severity="info">
          <msg>Command failed</msg>
          <details>Failed to something</details>
        </condition>
        
        <condition code="EC202020" severity="error">
          <msg>Mismatch</msg>
          <details>More Complex Details.</details>
        </condition>
        
        
      </conditions>
      
    </extension>
    <trID>
      <clTRID>20200227190249</clTRID>
      <svTRID>20200227200249880561-zuece8-reg839-NORID</svTRID>
    </trID>

  </response>

My code for all other is

$error = trim($results["EPP"]["RESPONSE"]["EXTENSION"]["CONDITIONS"]["CONDITION"]["DETAILS"]);

Please advice.

You would need to access the ‘attribute’ not the element value. However, since you haven’t posted how you are parsing the xml, no one cannot tell you how you would do so. You should also be looping over the child elements of ‘conditions’ since there are more than one.

At a rudimentary level, there is this. But it means hard coded values so that if a scheme changes, the would need to change as well.

$xml = simplexml_load_string($xml_str);
if( $xml->extension->conditions->condition->attributes()->code == "EC202020")
{
     // Do thing
}

I am using xml_parser

There should be an ATTRIBUTES array element, at the same level as the MSG and DETAILS elements, that then further contains a CODE element, containing the value.

If you use the following on your parsed data, you can see what it fully is -

echo '<pre>';
print_r($results);
Sponsor our Newsletter | Privacy Policy | Terms of Service