Documentation

XmlReader
in package

Convert XML string.

Table of Contents

Properties

$contents  : array<string, mixed>
$converter  : XmlConverter|null
$encoding  : string|null
$filename  : string|null
$path  : string|null
$root  : string|null
$rootAttributes  : array<string, mixed>
$rootNS  : array<string|int, string>
$validXml  : bool
$version  : string|null

Methods

__toString()  : string
Convert XML to string.
extract()  : mixed
Safely extract value from XML.
find()  : mixed
Search for a key in XML.
getContent()  : array<string, mixed>
Content of XML from root element.
getContents()  : array<string, mixed>
Content of XML from root element.
getConverter()  : XmlConverter|null
XML converter.
getEncoding()  : string|null
Encoding of XML.
getFilename()  : string|null
Filename of XML file.
getPath()  : string|null
Path of XML file.
getRoot()  : string|null
Value of root element.
getRootAttribute()  : mixed
Attribute of root element.
getRootAttributes()  : array<string, mixed>
Attributes of root element.
getRootNS()  : array<string|int, string>
Namespaces of root element.
getVersion()  : string|null
Version of XML.
isValidXml()  : bool
If XML is valid.
make()  : self
parseAttributes()  : array<string, mixed>|null
Parse attributes of entry, if entry has `@attributes` key.
parseContent()  : mixed
Parse content of entry, if entry has `@content` key, return only the value of `@content` otherwise return the entry.
save()  : bool
Save XML to file.
search()  : mixed
Search for a key in XML.
toArray()  : array<string, mixed>
Convert XML to array.
__construct()  : mixed
findValuesBySimilarKey()  : array<string|int, mixed>
parseConverter()  : void

Properties

$contents

protected array<string, mixed> $contents = []

$encoding

protected string|null $encoding = null

$filename

protected string|null $filename = null

$rootAttributes

protected array<string, mixed> $rootAttributes = []

$rootNS

protected array<string|int, string> $rootNS = []

$version

protected string|null $version = null

Methods

__toString()

Convert XML to string.

public __toString() : string
Return values
string

extract()

Safely extract value from XML.

public extract(array<string|int, string>|string $keys) : mixed
Parameters
$keys : array<string|int, string>|string

Keys to extract

find()

Search for a key in XML.

public find(string $key[, bool $strict = true ][, bool $content = false ][, bool $attributes = false ]) : mixed
Parameters
$key : string

Key to search

$strict : bool = true

If true, search for exact key. Default: true.

$content : bool = false

If true, get @content directly (if exists). Default: false.

$attributes : bool = false

If true, get @attributes directly (if exists). Default: false.

getContent()

Content of XML from root element.

public getContent() : array<string, mixed>

Use getContents() instead.

Return values
array<string, mixed>

getContents()

Content of XML from root element.

public getContents() : array<string, mixed>
Return values
array<string, mixed>

getEncoding()

Encoding of XML.

public getEncoding() : string|null
Return values
string|null

getFilename()

Filename of XML file.

public getFilename() : string|null
Return values
string|null

getPath()

Path of XML file.

public getPath() : string|null
Return values
string|null

getRoot()

Value of root element.

public getRoot() : string|null
Return values
string|null

getRootAttribute()

Attribute of root element.

public getRootAttribute(string $key) : mixed
Parameters
$key : string

getRootAttributes()

Attributes of root element.

public getRootAttributes() : array<string, mixed>
Return values
array<string, mixed>

getRootNS()

Namespaces of root element.

public getRootNS() : array<string|int, string>
Return values
array<string|int, string>

getVersion()

Version of XML.

public getVersion() : string|null
Return values
string|null

isValidXml()

If XML is valid.

public isValidXml() : bool
Return values
bool

make()

public static make(string $xml[, bool $mapContent = true ][, bool $failOnError = true ]) : self
Parameters
$xml : string

XML string or path to XML file

$mapContent : bool = true

If a key has only @content key, return only the value of @content. Default: true.

$failOnError : bool = true

Throw exception if XML is invalid. Default: true.

Tags
throws
Exception
Return values
self

parseAttributes()

Parse attributes of entry, if entry has `@attributes` key.

public static parseAttributes(mixed $entry) : array<string, mixed>|null
Parameters
$entry : mixed
Return values
array<string, mixed>|null

parseContent()

Parse content of entry, if entry has `@content` key, return only the value of `@content` otherwise return the entry.

public static parseContent(mixed $entry) : mixed
Parameters
$entry : mixed

save()

Save XML to file.

public save(string $path) : bool
Parameters
$path : string
Return values
bool

Search for a key in XML.

public search(string $key) : mixed
Parameters
$key : string

Key to search

toArray()

Convert XML to array.

public toArray() : array<string, mixed>
Return values
array<string, mixed>

__construct()

protected __construct([string|null $path = null ][, string|null $filename = null ][, bool $validXml = false ]) : mixed
Parameters
$path : string|null = null
$filename : string|null = null
$validXml : bool = false

findValuesBySimilarKey()

private findValuesBySimilarKey(array<string|int, mixed> $array, string $search[, bool $strict = false ][, int $index = 0 ]) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>
$search : string
$strict : bool = false
$index : int = 0
Return values
array<string|int, mixed>

parseConverter()

private parseConverter() : void

        
On this page

Search results