Hal\Resource::getXML PHP Method

getXML() public method

public getXML ( SimpleXMLElemen\SimpleXMLElement | null $xml = null ) : SimpleXMLElement
$xml SimpleXMLElemen\SimpleXMLElement | null
return SimpleXMLElement
    public function getXML($xml = null)
    {
        if (!$xml instanceof SimpleXMLElement) {
            $xml = new SimpleXMLElement('<resource></resource>');
        }
        $this->_xml = $xml;
        $this->setXMLAttributes($this->_xml, $this->getSelf());
        foreach ($this->_links as $links) {
            if (is_array($links)) {
                foreach ($links as $link) {
                    $this->_addLinks($link);
                }
            } else {
                $this->_addLinks($links);
            }
        }
        $this->_addData($this->_xml, $this->_data);
        $this->_getEmbedded($this->_embedded);
        return $this->_xml;
    }

Usage Example

 /**
  * Converts the give HAL Resource to a plain text representation that can be returned in the response.
  *
  * @param string        $format
  * @param \Hal\Resource $resource
  *
  * @throws NotAcceptableHttpException
  *
  * @return string
  */
 protected function convertResourceToPlainText($format, Resource $resource)
 {
     switch ($format) {
         case 'xml':
             return (string) $resource->getXML()->asXml();
         case 'json':
             return (string) $resource;
         default:
             throw new NotAcceptableHttpException();
     }
 }
All Usage Examples Of Hal\Resource::getXML