13use UtfNormal\Validator;
35 public static function element( $element, $attribs =
null, $contents =
'',
38 $out =
'<' . $element;
39 if ( $attribs !==
null ) {
42 if ( $contents ===
null ) {
44 } elseif ( $allowShortTag && $contents ===
'' ) {
48 $out .=
'>' . htmlspecialchars( $contents, ENT_NOQUOTES ) .
"</$element>";
62 if ( $attribs ===
null ) {
66 foreach ( $attribs as $name => $val ) {
67 $out .=
" {$name}=\"" . Sanitizer::encodeAttribute( $val ) .
'"';
83 public static function elementClean( $element, $attribs = [], $contents =
'' ) {
85 $attribs = array_map( Validator::cleanUp( ... ), $attribs );
111 return "</$element>";
127 public static function tags( $element, $attribs, $contents ) {
142 private static function isWellFormed( $text ) {
143 $parser = xml_parser_create(
"UTF-8" );
145 # case folding violates XML standard, turn it off
146 xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 );
148 if ( !xml_parse( $parser, $text,
true ) ) {
164 Sanitizer::hackDocType() .
169 return self::isWellFormed( $html );
182 [
'"',
'>',
'<' ],
188class_alias( Xml::class,
'Xml' );