QueryPath\DOMQuery::xml PHP Метод

xml() публичный Метод

Like {@link html()}, this functions in both a setter and a getter mode. In setter mode, the string passed in will be parsed and then appended to the elements wrapped by this DOMNode object.When in setter mode, this parses the XML using the DOMFragment parser. For that reason, an XML declaration is not necessary. In getter mode, the first element wrapped by this DOMNode object will be converted to an XML string and returned.
См. также: xhtml()
См. также: html()
См. также: text()
См. также: content()
См. также: innerXML()
public xml ( string $markup = null ) : mixed
$markup string A string containing XML data.
Результат mixed If markup is passed in, a DOMQuery is returned. If no markup is passed in, XML representing the first matched element is returned.
    public function xml($markup = null)
    {
        $omit_xml_decl = $this->options['omit_xml_declaration'];
        if ($markup === true) {
            // Basically, we handle the special case where we don't
            // want the XML declaration to be displayed.
            $omit_xml_decl = true;
        } elseif (isset($markup)) {
            if ($this->options['replace_entities']) {
                $markup = \QueryPath\Entities::replaceAllEntities($markup);
            }
            $doc = $this->document->createDocumentFragment();
            $doc->appendXML($markup);
            $this->removeChildren();
            $this->append($doc);
            return $this;
        }
        $length = $this->size();
        if ($length == 0) {
            return;
        }
        // Only return the first item -- that's what JQ does.
        $first = $this->getFirstMatch();
        // Catch cases where first item is not a legit DOM object.
        if (!$first instanceof \DOMNode) {
            return;
        }
        if ($first instanceof \DOMDocument || $first->isSameNode($first->ownerDocument->documentElement)) {
            return $omit_xml_decl ? $this->document->saveXML($first->ownerDocument->documentElement) : $this->document->saveXML();
        }
        return $this->document->saveXML($first);
    }