Constantes pré-définies

Ces constantes sont définies par cette extension, et ne sont disponibles que si cette extension a été compilée avec PHP, ou bien chargée au moment de l'exécution.

LIBXML_BIGLINES (int)
Permet de signaler correctement les numéros de ligne supérieurs à 65535.

Note:

Uniquement disponible dans PHP 7.0.0 avec Libxml >= 2.9.0

LIBXML_COMPACT (int)
Active l'optimisation de l'allocation de petits nœuds. Ceci pourrait augmenter la rapidité de votre application sans avoir besoin de changer votre code.

Note:

Seulement disponible dans Libxml >= 2.6.21

LIBXML_DTDATTR (int)
Attribut de DTD par défaut
LIBXML_DTDLOAD (int)
Charge le sous-ensemble externe
LIBXML_DTDVALID (int)
Valide avec la DTD
Attention

Activer la validation du DTD peut faciliter les attaques par entités externes XML (XXE).

LIBXML_HTML_NOIMPLIED (int)
Définit le drapeau HTML_PARSE_NOIMPLIED, qui désactive l'ajout automatique des éléments html/body...

Note:

Uniquement disponible en Libxml >= 2.7.7 (depuis PHP >= 5.4.0)

LIBXML_HTML_NODEFDTD (int)
Définit le drapeau HTML_PARSE_NODEFDTD, qui empèche l'ajout automatique d'un doctype si aucun n'est trouvé.

Note:

Only available in Libxml >= 2.7.8 (as of PHP >= 5.4.0)

LIBXML_NOBLANKS (int)
Suppression des nœuds vides
LIBXML_NOCDATA (int)
Fusion des CDATA en nœuds de texte
LIBXML_NOEMPTYTAG (int)
Agrandit les balises vides (par exemple, <br/> en <br></br>)

Note:

Cette option est actuellement disponible uniquement avec les fonctions DOMDocument::save et DOMDocument::saveXML.

LIBXML_NOENT (int)
Substitution des entités
Attention

Activer la substitution d'entiter peut faciliter les attaques XML External Entity (XXE).

LIBXML_NOERROR (int)
Suppression du rapport d'erreur
LIBXML_NONET (int)
Désactivation du réseau lors du chargement de document
LIBXML_NOWARNING (int)
Suppression des rapports d'alerte
LIBXML_NOXMLDECL (int)
Annule la déclaration XML lors de la sauvegarde du document

Note:

Seulement disponible dans Libxml >= 2.6.21

LIBXML_NSCLEAN (int)
Suppression des espaces de noms redondants
LIBXML_PARSEHUGE (int)
Affecte le drapeau XML_PARSE_HUGE. Désactive toute limite du parseur codée en dur. Ceci affecte les limites comme la profondeur maximale d'un document ou l'entité récursion, mais aussi les limites de la taille du texte des nœuds.

Note:

Seulement disponible depuis Libxml >= 2.7.0 (depuis PHP >= 5.3.2 et PHP >= 5.2.12)

LIBXML_PEDANTIC (int)
Définit le drapeau XML_PARSE_PEDANTIC, qui active le rapport d'erreur pedantic.

Note:

Available as of PHP >= 5.4.0

LIBXML_XINCLUDE (int)
Implémentation de la substitution XInclude
LIBXML_ERR_ERROR (int)
Erreur non-fatale
LIBXML_ERR_FATAL (int)
Erreur fatale
LIBXML_ERR_NONE (int)
Aucune erreur
LIBXML_ERR_WARNING (int)
Une alerte simple
LIBXML_VERSION (int)
libxml version sous la forme 20605 ou 20617
LIBXML_DOTTED_VERSION (string)
libxml version sous la forme 2.6.5 ou 2.6.17
LIBXML_SCHEMA_CREATE (int)
Crée la valeur par défaut/fixée du nœud durant la validation du schéma XSD

Note:

Uniquement disponible en Libxml >= 2.6.14 (à partir de PHP >= 5.5.2)

add a note add a note

User Contributed Notes 4 notes

up
11
@oneseventeen
13 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
vetalstar at mail dot ru
6 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
siraic at gmail dot com
2 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
-1
zachatwork at gmail dot com
14 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