Get a value from SimpleXML from SOAP api response using PHP

  api, php, soap, xml

I am trying to get a value from SimpleXML SOAP api response using PHP.

This is the PHP code

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://micros-hosting.com/EGateway/SimphonyPosApiWeb.asmx");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);

curl_setopt($ch, CURLOPT_POST, TRUE);

curl_setopt($ch, CURLOPT_POSTFIELDS, "<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetConfigurationInfo xmlns="http://micros-hosting.com/EGateway/">
      <vendorCode />
      <employeeObjectNum>90009</employeeObjectNum>
      <configurationInfoType>
        <int>1</int>
      </configurationInfoType>
      <revenueCenter>11</revenueCenter>
      <configInfoResponse />
    </GetConfigurationInfo>
  </soap:Body>
</soap:Envelope>");

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  "Content-Type: text/xml;",
  "SOAPAction: http://micros-hosting.com/EGateway/GetConfigurationInfo"
));

$response = curl_exec($ch);

curl_close($ch);


$xml = simplexml_load_string($response, NULL, NULL, "http://micros-hosting.com/EGateway/");
$ns = $xml->getNamespaces(true);
$soap = $xml->children($ns['soap']);
$res = $soap->Body->children();
print_r($res);

This is the response

SimpleXMLElement Object
(
    [GetConfigurationInfoResponse] => SimpleXMLElement Object
        (
            [configInfoResponse] => SimpleXMLElement Object
                (
                    [OperationalResult] => SimpleXMLElement Object
                        (
                            [Success] => true
                            [ErrorCode] => Success
                            [ErrorMessage] => Success
                        )

                    [ConfigInfoType] => SimpleXMLElement Object
                        (
                            [EConfigurationInfoType] => MENUITEMDEFINITIONS
                        )

                    [MenuItemDefinitions] => <?xml version="1.0" encoding="utf-8"?><?micros-type Micros.PosCore.DataStore.DbRecords.DbMenuItemDefinition[], PosCore, Version=2.5.0.0, Culture=neutral, PublicKeyToken=null?><ArrayOfDbMenuItemDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><DbMenuItemDefinition><NameOptions>0000000</NameOptions><MenuItemDefID>3740</MenuItemDefID><HierStrucID>23</HierStrucID><MenuItemMasterID>1572</MenuItemMasterID><SequenceNum>1</SequenceNum><Name1><StringNumberId>7848</StringNumberId><StringText>=Salad &amp; Appetizers=</StringText></Name1><Name2><StringNumberId>7849</StringNumberId><StringText /></Name2><SluSort>0</SluSort><NluNumber>0</NluNumber><Tare>0</Tare><Surcharge>0</Surcharge><IconNumber>0</IconNumber><OptionBits>00000000</OptionBits><SpecialCount>0</SpecialCount><PrepTime>0</PrepTime><Name3><StringNumberId>0</StringNumberId><StringText /></Name3><LongDescriptor><StringNumberId>0</StringNumberId><StringText /></LongDescriptor><MenuItemClassObjNum>0</MenuItemClassObjNum><NluGroupIndex>0</NluGroupIndex><SluIndex>0</SluIndex><HhtSluIndex>0</HhtSluIndex><MainLevels>00000000</MainLevels><SubLevels>00000000</SubLevels><PosRef>0</PosRef><PrintClassObjNum>0</PrintClassObjNum><PrefixLevelOverride>0</PrefixLevelOverride><GuestCount>0</GuestCount><MenuLevelEntries /><DefaultCondiments /><NextScreen /><MiMasterObjNum>10030000</MiMasterObjNum><CheckAvailability>false</CheckAvailability><OutOfMenuItem>false</OutOfMenuItem></DbMenuItemDefinition><DbMenuItemDefinition><NameOptions>0000000</NameOptions><MenuItemDefID>3741</MenuItemDefID><HierStrucID>23</HierStrucID><MenuItemMasterID>2090</MenuItemMasterID><SequenceNum>1</SequenceNum><Name1><StringNumberId>7850</StringNumberId><StringText>Chicken caesar salad</StringText></Name1><Name2><StringNumberId>7851</StringNumberId><StringText /></Name2><SluSort>0</SluSort><NluNumber>0</NluNumber><Tare>0</Tare><Surcharge>0</Surcharge><IconNumber>0</IconNumber><OptionBits>00000000</OptionBits><SpecialCount>0</SpecialCount><PrepTime>0</PrepTime><Name3><StringNumberId>0</StringNumberId><StringText /></Name3><LongDescriptor><StringNumberId>0</StringNumberId><StringText /></LongDescriptor><MenuItemClassObjNum>1000</MenuItemClassObjNum><NluGroupIndex>0</NluGroupIndex><SluIndex>4</SluIndex><HhtSluIndex>0</HhtSluIndex><MainLevels>11111111</MainLevels><SubLevels>11111111</SubLevels><PosRef>0</PosRef><PrintClassObjNum>503</PrintClassObjNum><PrefixLevelOverride>0</PrefixLevelOverride><GuestCount>0</GuestCount><MenuLevelEntries /><DefaultCondiments /><NextScreen /><MiMasterObjNum>10030002</MiMasterObjNum><CheckAvailability>false</CheckAvailability><OutOfMenuItem>false</OutOfMenuItem></DbMenuItemDefinition></ArrayOfDbMenuItemDefinition>
                )
        )
)       

I need get a value from MenuItemDefinitions response XML. How can I get a get a value from SimpleXML? Can someone help me on this?

Source: Ask PHP

LEAVE A COMMENT