XMLReader クラス

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

はじめに

XMLReader 拡張モジュールは、プル型の XML パーサーです。ドキュメント ストリーム内をカーソル風に進んでいき、その途中の各ノードで立ち止まります。

クラス概要

class XMLReader {
/* 定数 */
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;
/* プロパティ */
public int $depth;
public bool $hasValue;
public string $name;
public int $nodeType;
public string $prefix;
public string $value;
/* メソッド */
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
}

プロパティ

attributeCount

ノード上の属性の数

baseURI

ノードのベース URI

depth

ツリー内でのノードの階層 (0 から数える)

hasAttributes

ノードが属性を保持しているかどうか

hasValue

ノードがテキストの値を保持しているかどうか

isDefault

属性が DTD のデフォルトかどうか

isEmptyElement

ノードが空要素のタグかどうか

localName

ノードのローカル名

name

ノードの限定名

namespaceURI

ノードに関連付けられた名前空間の URI

nodeType

ノードの型

prefix

ノードに関連付けられた名前空間のプレフィックス

value

ノードのテキスト値

xmlLang

ノードが存在する xml:lang スコープ

定義済み定数

XMLReader ノード型

XMLReader::NONE

ノード型なし

XMLReader::ELEMENT

開始要素

XMLReader::ATTRIBUTE

属性ノード

XMLReader::TEXT

テキストノード

XMLReader::CDATA

CDATA ノード

XMLReader::ENTITY_REF

エンティティ参照ノード

XMLReader::ENTITY

エンティティ宣言ノード

XMLReader::PI

処理命令 (Processing Instruction) ノード

XMLReader::COMMENT

コメントノード

XMLReader::DOC

文書ノード

XMLReader::DOC_TYPE

文書型ノード

XMLReader::DOC_FRAGMENT

文書片ノード

XMLReader::NOTATION

記法ノード

XMLReader::WHITESPACE

Whitespace ノード

XMLReader::SIGNIFICANT_WHITESPACE

Significant Whitespace ノード

XMLReader::END_ELEMENT

終了要素

XMLReader::END_ENTITY

終了エンティティ

XMLReader::XML_DECLARATION

XML 宣言ノード

XMLReader パーサーオプション

XMLReader::LOADDTD

DTD を読み込むが、妥当性は検証しない

XMLReader::DEFAULTATTRS

DTD およびデフォルト属性を読み込むが、妥当性は検証しない

XMLReader::VALIDATE

DTD を読み込み、パース時に妥当性を検証する

XMLReader::SUBST_ENTITIES

エンティティを参照で置き換える

変更履歴

バージョン 説明
8.4.0 クラス定数が型付けされました。

目次