Horde_Xml_Element::saveXmlFragment PHP Method

saveXmlFragment() public method

Returns a string of this element's XML without prologue.
public saveXmlFragment ( $formatted = false ) : string
return string
    public function saveXmlFragment($formatted = false)
    {
        $oldFormatted = $this->_element->ownerDocument->formatOutput;
        $this->_element->ownerDocument->formatOutput = $formatted;
        $xml = $this->_element->ownerDocument->saveXML($this->_element);
        $this->_element->ownerDocument->formatOutput = $oldFormatted;
        return $xml;
    }

Usage Example

Exemplo n.º 1
0
 public function testFromArray()
 {
     $e = new Horde_Xml_Element('<element />');
     $e->fromArray(array('user' => 'Joe Schmoe', 'atom:title' => 'Test Title', 'child#href' => 'http://www.example.com/', '#title' => 'Test Element'));
     $this->assertEquals('<element title="Test Element"><user>Joe Schmoe</user><atom:title xmlns:atom="http://www.w3.org/2005/Atom">Test Title</atom:title><child href="http://www.example.com/"/></element>', $e->saveXmlFragment());
     $e = new Horde_Xml_Element('<element />');
     $e->fromArray(array('author' => array('name' => 'Joe', 'email' => '*****@*****.**')));
     $this->assertEquals('<element><author><name>Joe</name><email>[email protected]</email></author></element>', $e->saveXmlFragment());
 }