PHP 8.5.0 Alpha 2 available for testing

Constantes predefinidas

Estas constantes son definidas por esta extensión, y solo están disponibles si esta extensión ha sido compilada con PHP, o bien cargada en tiempo de ejecución.

LIBXML_BIGLINES (int)
Permite señalar correctamente los números de línea superiores a 65535.

Nota:

Disponible únicamente en PHP 7.0.0 con Libxml >= 2.9.0

LIBXML_COMPACT (int)
Activa la optimización de la asignación de pequeños nodos. Esto podría aumentar la rapidez de la aplicación sin necesidad de modificar el código.

Nota:

Disponible únicamente en Libxml >= 2.6.21

LIBXML_DTDATTR (int)
Atributo DTD por defecto
Precaución

Activar la carga de atributos DTD permitirá la recuperación de entidades externas. La constante LIBXML_NO_XXE puede ser utilizada para evitar esto (disponible únicamente en Libxml >= 2.13.0, a partir de PHP 8.4.0).

LIBXML_DTDLOAD (int)
Carga el subconjunto externo
Precaución

Activar la carga de subconjuntos externos permitirá la recuperación de entidades externas. La constante LIBXML_NO_XXE puede ser utilizada para evitar esto (disponible únicamente en Libxml >= 2.13.0, a partir de PHP 8.4.0).

LIBXML_DTDVALID (int)
Valida con la DTD
Precaución

Activar la validación de DTD puede facilitar ataques por entidades externas XML (XXE). La constante LIBXML_NO_XXE puede ser utilizada para evitar esto (disponible únicamente en Libxml >= 2.13.0, a partir de PHP 8.4.0).

LIBXML_HTML_NOIMPLIED (int)
Define el flag HTML_PARSE_NOIMPLIED, que desactiva la adición automática de elementos html/body...

Nota:

Disponible únicamente en Libxml >= 2.7.7 (desde PHP >= 5.4.0)

LIBXML_HTML_NODEFDTD (int)
Define el flag HTML_PARSE_NODEFDTD, que impide la adición automática de un doctype si no se encuentra ninguno.

Nota:

Disponible únicamente en Libxml >= 2.7.8 (desde PHP >= 5.4.0)

LIBXML_LOADED_VERSION (string)
Versión del módulo principal del analizador libxml.
LIBXML_NOBLANKS (int)
Eliminación de nodos vacíos
LIBXML_NOCDATA (int)
Fusión de CDATA en nodos de texto
LIBXML_NOEMPTYTAG (int)
Expande las etiquetas vacías (por ejemplo, <br/> en <br></br>)

Nota:

Esta opción está actualmente disponible únicamente con las funciones DOMDocument::save y DOMDocument::saveXML.

LIBXML_NOENT (int)
Sustitución de entidades
Precaución

Activar la sustitución de entidades puede facilitar ataques XML External Entity (XXE).

LIBXML_NOERROR (int)
Supresión de informes de error
LIBXML_NONET (int)
Desactivación de la red durante la carga de documentos
LIBXML_NOWARNING (int)
Supresión de informes de advertencia
LIBXML_NOXMLDECL (int)
Anula la declaración XML durante la guardado del documento

Nota:

Disponible únicamente en Libxml >= 2.6.21

LIBXML_NO_XXE (int)
Desactiva las entidades externas XML (XXE) durante la sustitución de entidades

Nota:

Disponible únicamente en Libxml >= 2.13.0, a partir de PHP 8.4.0

LIBXML_NSCLEAN (int)
Eliminación de espacios de nombres redundantes
LIBXML_PARSEHUGE (int)
Afecta al flag XML_PARSE_HUGE. Desactiva cualquier límite del analizador codificado en el código. Esto afecta a límites como la profundidad máxima de un documento o la recursión de entidades, pero también a los límites del tamaño del texto de los nodos.

Nota:

Disponible únicamente desde Libxml >= 2.7.0 (desde PHP >= 5.3.2 y PHP >= 5.2.12)

LIBXML_PEDANTIC (int)
Define el flag XML_PARSE_PEDANTIC, que activa el informe de error pedantic.

Nota:

Disponible a partir de PHP >= 5.4.0

LIBXML_RECOVER (int)
Activa el modo de recuperación durante el análisis de un documento.

Nota:

Disponible únicamente a partir de PHP 8.4.0

LIBXML_XINCLUDE (int)
Implementación de la sustitución XInclude
LIBXML_ERR_ERROR (int)
Error no fatal
LIBXML_ERR_FATAL (int)
Error fatal
LIBXML_ERR_NONE (int)
Ningún error
LIBXML_ERR_WARNING (int)
Una advertencia simple
LIBXML_VERSION (int)
Versión de libxml en formato 20605 o 20617
LIBXML_DOTTED_VERSION (string)
Versión de libxml en formato 2.6.5 o 2.6.17
LIBXML_SCHEMA_CREATE (int)
Crea el valor por defecto/fijo del nodo durante la validación del esquema XSD

Nota:

Disponible únicamente en Libxml >= 2.6.14 (a partir de PHP >= 5.5.2)

add a note

User Contributed Notes 5 notes

up
10
@oneseventeen
14 years ago
When inserting XML DOM Elements inside existing XML DOM Elements that I loaded from an XML file using the following code, none of my new elements were formatted correctly, they just showed up on one line:

<?php
$dom
= DOMDocument::load('file.xml');
$dom->formatOutput = true;
//$dom->add some new elements with child nodes somewhere inside the loaded XML using insertBefore();
$dom->saveXML();
//output: everything looks normal but the new nodes are all on one line.
?>

I found I could pass LIBXML_NOBLANKS to the load method and it would reformat the whole document, including my added stuff:
<?php
$dom
= DOMDocument::load('file.xml', LIBXML_NOBLANKS);
$dom->formatOutput = true;
//$dom->add some new elements with child nodes somewhere inside the loaded XML using insertBefore();
$dom->saveXML();
//output: everything looks newly formatted, including new nodes
?>

Hope this helps, took me hours of trial and error to figure this out!
up
2
siraic at gmail dot com
4 years ago
The name of the constant LIBXML_NOENT is very misleading. Adding this flag actually causes the parser to load and insert the external entities. Omitting it leaves the tags untouched, which is probably what you want.
up
2
vetalstar at mail dot ru
7 years ago
LIBXML_DOTTED_VERSION option doesn't work.
libxml version: 2.9.4

<?php

echo LIBXML_DOTTED_VERSION;
$xml = new SimpleXMLElement('<fasa_request id="1234567"/>', LIBXML_NOXMLDECL);

?>
up
0
Ismael Miguel
2 years ago
If you want to save without the XML declaration, and LIBXML_NOXMLDECL doesn't work for you, you can just do this:

<?php
$doc
= new \DOMDocument('1.0', 'UTF-8');
$doc->loadXML($xml, LIBXML_*);

echo
$doc->saveXML($doc->firstElementChild);
?>

This will output the XML without the XML declaration and without using the flag.
You also don't need to do fiddly replacements and pray that it works.
up
0
zachatwork at gmail dot com
15 years ago
Note: The LIBXML_NOXMLDECL constant is defined in this library but is not supported by DOMDocument (yet).

See also: http://bugs.php.net/bug.php?id=47137

<?php

print "PHP_VERSION: ".PHP_VERSION."\n";
print
"LIBXML_VERSION: ".LIBXML_VERSION."\n";
print
"LIBXML_NOXMLDECL: ".LIBXML_NOXMLDECL."\n";

$dom = new DomDocument();
$dom->loadXML("<foo />");

# This should work but doesn't.

print "DOMDocument doesn't honor LIBXML_NOXMLDECL:\n";
print
$dom->saveXML(null,LIBXML_NOXMLDECL);

# This works, and will still work after the above is fixed.

print "Forwards compatible workaround:\n";
$lines = explode("\n", $dom->saveXML(null, LIBXML_NOXMLDECL), 2);
if(!
preg_match('/^\<\?xml/', $lines[0]))
print
$lines[0];
print
$lines[1];

?>

PHP_VERSION: 5.3.1-0.dotdeb.1
LIBXML_VERSION: 20632
LIBXML_NOXMLDECL: 2
DOMDocument doesn't honor LIBXML_NOXMLDECL:
<?xml version="1.0"?>
<foo/>
Forwards compatible workaround:
<foo/>
To Top