JAXLXml::to_string PHP Method

to_string() public method

public to_string ( string $parent_ns = null ) : string
$parent_ns string
return string
    public function to_string($parent_ns = null)
    {
        $xml = '';
        $xml .= '<' . $this->name;
        if ($this->ns && $this->ns != $parent_ns) {
            $xml .= ' xmlns="' . $this->ns . '"';
        }
        foreach ($this->attrs as $k => $v) {
            if (!is_null($v) && $v !== false) {
                $xml .= ' ' . $k . '="' . htmlspecialchars($v) . '"';
            }
        }
        $xml .= '>';
        foreach ($this->children as $child) {
            $xml .= $child->to_string($this->ns);
        }
        if ($this->xml !== null) {
            $xml .= $this->xml;
        }
        if ($this->text !== null) {
            $xml .= htmlspecialchars($this->text);
        }
        $xml .= '</' . $this->name . '>';
        return $xml;
    }

Usage Example

コード例 #1
0
 function test_xmpp_stanza_nested()
 {
     $stanza = new JAXLXml('message', array('to' => '[email protected]', 'from' => '[email protected]'));
     $stanza->c('body')->attrs(array('xml:lang' => 'en'))->t('hello')->up()->c('thread')->t('1234')->up()->c('nested')->c('nest')->t('nest1')->up()->c('nest')->t('nest2')->up()->c('nest')->t('nest3')->up()->up()->c('c')->attrs(array('hash' => '84jsdmnskd'));
     $this->assertEquals('<message to="[email protected]" from="[email protected]"><body xml:lang="en">hello</body><thread>1234</thread><nested><nest>nest1</nest><nest>nest2</nest><nest>nest3</nest></nested><c hash="84jsdmnskd"></c></message>', $stanza->to_string());
 }
All Usage Examples Of JAXLXml::to_string