La classe XMLReader

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

Introduction

L'extension XMLReader est un analyseur XML. L'analyseur fonctionne comme un curseur qui parcourt le document et s'arrête sur chaque nœud.

Synopsis de la classe

class XMLReader {
/* Constantes */
public const int NONE;
public const int ELEMENT;
public const int ATTRIBUTE;
public const int TEXT;
public const int CDATA;
public const int ENTITY_REF;
public const int ENTITY;
public const int PI;
public const int COMMENT;
public const int DOC;
public const int DOC_TYPE;
public const int DOC_FRAGMENT;
public const int NOTATION;
public const int WHITESPACE;
public const int END_ELEMENT;
public const int END_ENTITY;
public const int XML_DECLARATION;
public const int LOADDTD;
public const int DEFAULTATTRS;
public const int VALIDATE;
public const int SUBST_ENTITIES;
/* Propriétés */
public int $depth;
public bool $hasValue;
public string $name;
public int $nodeType;
public string $prefix;
public string $value;
/* Méthodes */
public function close(): true
public function expand(?DOMNode $baseNode = null): DOMNode|false
public static function fromStream(
    resource $stream,
    ?string $encoding = null,
    int $flags = 0,
    ?string $documentUri = null
): static
public static function fromString(string $source, ?string $encoding = null, int $flags = 0): static
public static function fromUri(string $uri, ?string $encoding = null, int $flags = 0): static
public function getAttribute(string $name): ?string
public function getAttributeNo(int $index): ?string
public function getAttributeNs(string $name, string $namespace): ?string
public function getParserProperty(int $property): bool
public function isValid(): bool
public function lookupNamespace(string $prefix): ?string
public function moveToAttribute(string $name): bool
public function moveToAttributeNo(int $index): bool
public function moveToAttributeNs(string $name, string $namespace): bool
public function moveToElement(): bool
public function moveToFirstAttribute(): bool
public function moveToNextAttribute(): bool
public function next(?string $name = null): bool
public static function open(string $uri, ?string $encoding = null, int $flags = 0): XMLReader
public function open(string $uri, ?string $encoding = null, int $flags = 0): bool
public function read(): bool
public function readInnerXml(): string
public function readOuterXml(): string
public function readString(): string
public function setParserProperty(int $property, bool $value): bool
public function setRelaxNGSchema(?string $filename): bool
public function setRelaxNGSchemaSource(?string $source): bool
public function setSchema(?string $filename): bool
public static function XML(string $source, ?string $encoding = null, int $flags = 0): XMLReader
public function XML(string $source, ?string $encoding = null, int $flags = 0): bool
}

Propriétés

attributeCount

Le nombre d'attributs dans le nœud

baseURI

La base URI du nœud

depth

Profondeur du nœud dans l'arbre démarrant à 0

hasAttributes

Indique si le nœud a des attributs

hasValue

Indique si le nœud a une valeur de texte

isDefault

Indique si l'attribut tire sa valeur par défaut de la DTD

isEmptyElement

Indique si le nœud est un élément vide

localName

Le nom local du nœud

name

Le nom qualifié du nœud

namespaceURI

L'URI de l'espace de noms associé au nœud

nodeType

Le type de nœud pour le nœud

prefix

Le préfixe de l'espace de noms associé au nœud

value

La valeur du texte du nœud

xmlLang

La portée xml:lang dans laquelle le nœud réside

Constantes pré-définies

Types de nœuds XMLReader

XMLReader::NONE

Pas de type de nœud

XMLReader::ELEMENT

Élément de départ

XMLReader::ATTRIBUTE

Nœud Attribut

XMLReader::TEXT

Nœud texte

XMLReader::CDATA

Nœud CDATA

XMLReader::ENTITY_REF

Nœud de référence d'entité

XMLReader::ENTITY

Nœud de déclaration d'entité

XMLReader::PI

Nœud d'instruction de processus

XMLReader::COMMENT

Nœud de commentaire

XMLReader::DOC

Nœud document

XMLReader::DOC_TYPE

Nœud de type de document

XMLReader::DOC_FRAGMENT

Nœud de fragment de document

XMLReader::NOTATION

Nœud de notation

XMLReader::WHITESPACE

Nœud "espace"

XMLReader::SIGNIFICANT_WHITESPACE

Nœud "espace" significatif

XMLReader::END_ELEMENT

Élément de fin

XMLReader::END_ENTITY

Entité de fin

XMLReader::XML_DECLARATION

Nœud de déclaration XML

Options de l'analyseur XMLReader

XMLReader::LOADDTD

Charge une DTD mais ne la valide pas

XMLReader::DEFAULTATTRS

Charge une DTD et les attributs par défaut mais ne la valide pas

XMLReader::VALIDATE

Charge une DTD et valide le document au moment de l'analyse

XMLReader::SUBST_ENTITIES

Substitue les entités et étend les références

Historique

Version Description
8.4.0 Les constantes de classe sont désormais typées.

Sommaire