phpxmlroblox

How do I get the data from specific tag in xml php curl response


I need to get the <ns1:value></ns1:value> text from the http POST request with the following body

      <?xml version="1.0" encoding="UTF - 8"?>
      <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="http://roblox.com/RCCServiceSoap" xmlns:ns1="http://roblox.com/" xmlns:ns3="http://roblox.com/RCCServiceSoap12">
      <SOAP-ENV:Body>
          <ns1:OpenJob>
              <ns1:job>
                  <ns1:id>test</ns1:id>
                  <ns1:expirationInSeconds>30</ns1:expirationInSeconds>
                  <ns1:category>0</ns1:category>
                  <ns1:cores>1</ns1:cores>
                  </ns1:job>
                  <ns1:script>
                      <ns1:name>Script</ns1:name>
                      <ns1:script>
                          game.Players:createLocalPlayer(0) 
                          game.Players.LocalPlayer:LoadCharacter() 
  
                          return game:service("ThumbnailGenerator"):click("PNG", 512, 512, true)
                      </ns1:script>
                      <ns1:arguments></ns1:arguments>
                  </ns1:script>
              </ns1:OpenJob>
      </SOAP-ENV:Body>
      </SOAP-ENV:Envelope>

( this is a ROBLOX RCCService version 0.3.764.0 request )

I have tried to use simplexml_load_string($response) but that didn't work.


Solution

  • You can access it via using the Namespace SOAP-ENV and nsi which is inside the parent Namespace Body accessor.

    libxml_use_internal_errors(true);
    
    $ns1 = simplexml_load_string($xml)->children('SOAP-ENV', true)->Body->children('ns1', true);
    [$job, $script] = [$ns1->OpenJob->job, $ns1->OpenJob->script];
    
    var_dump($job, $script);
    

    You can read more on the docs or see a live example on 3v4l.org

    This is also covered well in the following SO post.