Convert xml/html code to a DOMXpath object.

@param String code The html/xml code to be parsed.
@param String type html|xml
@param String encoding

@return \DOMXPath
340882
protected static function toXpath($code, $type='html', $encoding='UTF-8') {
		$doc = new \DOMDocument();
		if ($type == 'xml')
			@$doc->loadXML('<?xml encoding="'.$encoding.'">' . $code);
		else
			@$doc->loadHTML('<?xml encoding="'.$encoding.'">' . $code);

		foreach($doc->childNodes as $item) {
			if($item->nodeType == XML_PI_NODE)
				$doc->removeChild($item); #remove encoding node
		}

		return new \DOMXPath($doc);
	}
316843
static function xpathQuery($html, $xpath) {
		$ddoc = new \DOMDocument();
		@$ddoc->loadHTML($html);
	
		$dxpath = new \DOMXPath($ddoc);
		return $dxpath->query($xpath);
	}
202051
public function mapLinkTypeCodeToColumnName($linkTypeCode)
    {

        // query whether or not the link type code has a mapping
        if (isset($this->linkTypeCodeToColumnNameMapping[$linkTypeCode])) {
            return $this->linkTypeCodeToColumnNameMapping[$linkTypeCode];
        }

        // return the passed link type code
        return $linkTypeCode;
    }
197405
public static function encodepath($text, $type = null)
    {
        $text = preg_replace('#[`\'"\^~{}\[\]()]#', '', $text);
        $text = preg_replace('#[\n\s\/\p{P}]#u', '-', $text);

        if ($type === self::UNICODE) {
            $text = preg_replace('#[^\d\p{L}\p{N}\-]#u', '', $text);
        } elseif ($type === self::ASCII) {
            $text = preg_replace('#[^\d\p{L}\-]#u', '', $text);
            $text = self::encodepath($text);
        } else {
            $text = Helper::toAscii($text);
            $text = preg_replace('#[^a-z\d\-]#i', '', $text);
        }

        return trim(preg_replace('#--+#', '-', $text), '-');
    }
1095843
static String encodeRaw(TypeMirror type) {
    StringBuilder sb = new StringBuilder();
    return type.accept(RAW_ENCODING_TYPE_VISITOR, sb).toString();
  }
1009513
private function isValidXmlTag( $code )
    {
        if ( $code[strlen( $code ) - 1] !== '/' )
        {
            $code .= '/';
        }
        $code .= '>';
        $code = '<' . str_replace(
            array( '<', '&' ),
            array( '&lt;', '&amp;' ),
            substr( $code, 1 )
        );
        $errorHanding = libxml_use_internal_errors( true );
        $simpleXml = simplexml_load_string( $code );
        libxml_use_internal_errors( $errorHanding );
        return ( $simpleXml !== false );
    }
433391
protected TypeCodec<?> createCodec(GenericType<?> javaType, boolean isJavaCovariant) {
    TypeToken<?> token = javaType.__getToken();
    if (List.class.isAssignableFrom(token.getRawType())
        && token.getType() instanceof ParameterizedType) {
      Type[] typeArguments = ((ParameterizedType) token.getType()).getActualTypeArguments();
      GenericType<?> elementType = GenericType.of(typeArguments[0]);
      TypeCodec<?> elementCodec = codecFor(elementType, isJavaCovariant);
      return TypeCodecs.listOf(elementCodec);
    } else if (Set.class.isAssignableFrom(token.getRawType())
        && token.getType() instanceof ParameterizedType) {
      Type[] typeArguments = ((ParameterizedType) token.getType()).getActualTypeArguments();
      GenericType<?> elementType = GenericType.of(typeArguments[0]);
      TypeCodec<?> elementCodec = codecFor(elementType, isJavaCovariant);
      return TypeCodecs.setOf(elementCodec);
    } else if (Map.class.isAssignableFrom(token.getRawType())
        && token.getType() instanceof ParameterizedType) {
      Type[] typeArguments = ((ParameterizedType) token.getType()).getActualTypeArguments();
      GenericType<?> keyType = GenericType.of(typeArguments[0]);
      GenericType<?> valueType = GenericType.of(typeArguments[1]);
      TypeCodec<?> keyCodec = codecFor(keyType, isJavaCovariant);
      TypeCodec<?> valueCodec = codecFor(valueType, isJavaCovariant);
      return TypeCodecs.mapOf(keyCodec, valueCodec);
    }
    throw new CodecNotFoundException(null, javaType);
  }
715012
function(xml) {
    var contexp, fn, formatted, indent, l, lastType, len, lines, ln, pad, reg, transitions, wsexp;
    reg = /(>)(<)(\/*)/g;
    wsexp = /[ ]*(.*)[ ]+\n/g;
    contexp = /(<.+>)(.+\n)/g;
    xml = xml.replace(reg, '$1\n$2$3').replace(wsexp, '$1\n').replace(contexp, '$1\n$2');
    pad = 0;
    formatted = '';
    lines = xml.split('\n');
    indent = 0;
    lastType = 'other';
    transitions = {
      'single->single': 0,
      'single->closing': -1,
      'single->opening': 0,
      'single->other': 0,
      'closing->single': 0,
      'closing->closing': -1,
      'closing->opening': 0,
      'closing->other': 0,
      'opening->single': 1,
      'opening->closing': 0,
      'opening->opening': 1,
      'opening->other': 1,
      'other->single': 0,
      'other->closing': -1,
      'other->opening': 0,
      'other->other': 0
    };
    fn = function(ln) {
      var fromTo, j, key, padding, type, types, value;
      types = {
        single: Boolean(ln.match(/<.+\/>/)),
        closing: Boolean(ln.match(/<\/.+>/)),
        opening: Boolean(ln.match(/<[^!?].*>/))
      };
      type = ((function() {
        var results;
        results = [];
        for (key in types) {
          value = types[key];
          if (value) {
            results.push(key);
          }
        }
        return results;
      })())[0];
      type = type === void 0 ? 'other' : type;
      fromTo = lastType + '->' + type;
      lastType = type;
      padding = '';
      indent += transitions[fromTo];
      padding = ((function() {
        var m, ref1, results;
        results = [];
        for (j = m = 0, ref1 = indent; 0 <= ref1 ? m < ref1 : m > ref1; j = 0 <= ref1 ? ++m : --m) {
          results.push('  ');
        }
        return results;
      })()).join('');
      if (fromTo === 'opening->closing') {
        formatted = formatted.substr(0, formatted.length - 1) + ln + '\n';
      } else {
        formatted += padding + ln + '\n';
      }
    };
    for (l = 0, len = lines.length; l < len; l++) {
      ln = lines[l];
      fn(ln);
    }
    return formatted;
  }
49908
function getCode(code, opts, attrs, url) {
  var type = getType(attrs),
    parserOpts = getParserOptions(attrs)

  //#if NODE
  // istanbul ignore else
  if (url) {
    var src = getAttr(attrs, 'src')
    if (src) {
      var
        charset = getAttr(attrs, 'charset'),
        file = path.resolve(path.dirname(url), src)
      code = require('fs').readFileSync(file, charset || 'utf8')
    }
  }
  //#endif
  return _compileJS(code, opts, type, parserOpts, url)
}
259826
public static function PurifyXHTML($html = null, $encoding = 'UTF-8') {

		$config = self::GetHTMLPurifierConfig();
		$config->set('Core.Encoding', $encoding);
		$config->set('HTML.Doctype', 'XHTML 1.0 Strict');
		$config->set('HTML.TidyLevel', 'heavy'); // all changes, minus...
		$config->set('CSS.AllowedProperties', array());
		$config->set('Attr.AllowedClasses', array());
		$config->set('HTML.Allowed', null);
		$config->set('AutoFormat.RemoveEmpty', true); // Remove empty tags
		$config->set('AutoFormat.Linkify', true);	// add <A> to links
		$config->set('AutoFormat.AutoParagraph', true);
		$config->set('HTML.ForbiddenElements', array('span', 'center'));
		$config->set('Core.EscapeNonASCIICharacters', true);
		$config->set('Output.TidyFormat', true);

		$purifier = new \HTMLPurifier($config);
		$html = $purifier->purify($html);

		// Rimpiazzo le parentesi quadre
		$html = str_ireplace("%5B", "[", $html);
		$html = str_ireplace("%5D", "]", $html);

		return $html;
	}
284290
private function parseTypeConfig(\DOMXPath $xpath, \DOMNode $typeRootNode)
    {
        $staticFields  = $this->parseMappingFields($xpath, $typeRootNode);
        $idFieldName   = $typeRootNode->getAttribute('idFieldName');
        $datasources   = $this->parseDatasources($xpath, $typeRootNode);

        $mappingParams = ['staticFields' => $staticFields];

        return ['mapping' => $mappingParams, 'idFieldName' => $idFieldName, 'datasources' => $datasources];
    }
228935
public function getXML( $version = '1.0', $encoding = 'UTF-8', $willFormatOutput = true )
    {
        if (is_null( self::$instance )) {
            self::$instance               = new \DOMDocument( $version, $encoding );
            self::$instance->formatOutput = $willFormatOutput;
        }

        return self::$instance;
    }
405082
public static function docPart($htmlPart, $encoding = 'utf-8', $docType = NULL) {
    if (!is_string($htmlPart))
      $htmlPart = self::export($htmlPart);
    
    if (mb_strpos(trim($htmlPart), '<!DOCTYPE') === 0) {
      $document = $htmlPart;
    } else {
      // DOMDocument setzt so oder so einen default, also können wir das auch explizit machen
      $docType = $docType ?: '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';

      // ebenso das encoding ist utf8
      $document  = $docType."\n";
      
      if (mb_strpos(trim($htmlPart),'<html') === 0) {
        $document .= $htmlPart;
      } else {
        $document .= '<html><head><meta http-equiv="Content-Type" content="text/html; charset='.$encoding.'"/></head><body>'.$htmlPart.'</body></html>';
      }
    }
    
    return self::doc($document);
  }
1116775
function isInvalidXmlChar(code) {
  if (typeof code == "string")
    code = code.charCodeAt(0);
  return (code >= 0x1 && code <= 0x8) ||
    (code >= 0xB && code <= 0xC) ||
    (code >= 0xE && code <= 0x1F) ||
    (code >= 0x7F && code <= 0x84) ||
    (code >= 0x86 && code <= 0x9F) ||
    (code >= 0xFDD0 && code <= 0xFDDF) ||
    (code % 0x10000 == 0xFFFE) ||
    (code % 0x10000 == 0xFFFF);
}
1259848
public function getPath($languageCode)
    {
        $route = $this->routes()->newQuery()
            ->where('language_code', $languageCode)
            ->first();
        if (empty($route->path)) {
            throw new DomainException("There is no route in '$languageCode' language for content: $this->id");
        }
        return $route->path;
    }
786486
private function loadTypes(&$tags, \DOMXPath $xpath, \DOMNode $context = null)
    {
        $result = [];

        /** @var \DOMElement $node */
        foreach ($xpath->query('x:types/x:type', $context) as $node) {
            $value = $this->loadType($xpath, $node, $tags);
            $result[$value['name']] = $value;
        }

        return $result;
    }
1320225
public static function toXml($data, $encoding = 'UTF-8')
    {
        header('Content-Type: text/xml');
        $xml = '<?xml version="1.0" encoding="' . $encoding . "\"?>\n";
        return $xml .= self::_to_xml_body($data);
    }