You are here

public function QueryPath::xml in QueryPath 6

Same name and namespace in other branches
  1. 7.3 QueryPath/QueryPath.php \QueryPath::xml()
  2. 7.2 QueryPath/QueryPath.php \QueryPath::xml()
1 call to QueryPath::xml()
QueryPath::xhtml in QueryPath/QueryPath.php

File

QueryPath/QueryPath.php, line 1340

Class

QueryPath

Code

public function xml($markup = NULL) {
  $omit_xml_decl = $this->options['omit_xml_declaration'];
  if ($markup === TRUE) {
    $omit_xml_decl = TRUE;
  }
  elseif (isset($markup)) {
    if ($this->options['replace_entities']) {
      $markup = QueryPathEntities::replaceAllEntities($markup);
    }
    $doc = $this->document
      ->createDocumentFragment();
    $doc
      ->appendXML($markup);
    $this
      ->removeChildren();
    $this
      ->append($doc);
    return $this;
  }
  $length = $this
    ->size();
  if ($length == 0) {
    return NULL;
  }
  $first = $this
    ->getFirstMatch();
  if (!$first instanceof DOMNode) {
    return NULL;
  }
  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);
}