xml_parser_set_option

(PHP 4, PHP 5, PHP 7, PHP 8)

xml_parser_set_optionConfigura las opciones en un intérprete XML

Descripción

xml_parser_set_option(XMLParser $parser, int $option, string|int $value): bool

Configura una opción en un intérprete XML.

Parámetros

parser

Identificador del recurso del intérprete XML sobre el que se va a configurar el valor de la opción.

option

Cual es la opción para configurar. Véase más abajo.

Estan disponibles las siguientes opciones:

Opciones del intérprete XML
Option constant Data type Description
XML_OPTION_CASE_FOLDING integer Controla si case-folding está activada para este intérprete XML. Por defecto activado.
XML_OPTION_SKIP_TAGSTART integer Especifica el número de caracteres que seran omitidos al principio del nombre de una etiqueta.
XML_OPTION_SKIP_WHITE integer Especifica si hay que omitir los valores que consistan en espacios en blanco.
XML_OPTION_TARGET_ENCODING string Configura cual será el target encoding (codificación de caracteres de salida) para usar en este intérprete XML. Por defecto se establece la misma codificación de la fuente fuente usada por xml_parser_create(). Las codificaciones de destino soportadas son ISO-8859-1, US-ASCII y UTF-8.

value

El nuevo valor para la opción.

Valores devueltos

Devuelve true si se ha establecido el nuevo valor para la opción. Puede devolver false si: parser no se refiere a un intérprete válido, o si la opción no se ha podido configurar.

Historial de cambios

Versión Descripción
8.0.0 parser expects an XMLParser instance now; previously, a valid xml resource was expected.
add a note

User Contributed Notes 3 notes

up
2
www.thomaskoch.it
15 years ago
The option XML_OPTION_SKIP_WHITE has no effect in my PHP 5.2.6 (with expat-1.95.8-5). To skip cdata composed of white space only, simply check for that at the beginning of your cdata callback function:

<?php
function callback_cdata($parser, $cdata)
{
if(!
trim($cdata))
return;

// ... continue processing ...
}
?>
up
1
pupeno at pupeno dot com
21 years ago
XML is case sensitive, then, from my point of view, disabling case folding doesn't goes against xml 1.0 specifications but the contrary, disabling case folding allow us to distiguish between diferent cases of the same letter ('a' and 'A') which of XML are two diferent things.
From my point of view, disabling case folding is a good practice and I think it should be disabled by default.
More information on:
http://www.isacat.net/2001/xml/case.htm
and
http://www.w3.org/TR/REC-xml
Thank you.
up
0
j[no_spam_please] at [thx]jessepearson dot net
17 years ago
In the function below, you need to update two lines if you don't want php to throw warnings.

change these two:
$elements[$index]['attributes'] = $tag['attributes'];
$elements[$index]['content'] = $tag['value'];

to this:
$elements[$index]['attributes'] = empty($tag['attributes']) ? "" : $tag['attributes'];
$elements[$index]['content'] = empty($tag['value']) ? "" : $tag['value'];
To Top