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
= []
$converter
protected
XmlConverter|null
$converter
= null
$encoding
protected
string|null
$encoding
= null
$filename
protected
string|null
$filename
= null
$path
protected
string|null
$path
= null
$root
protected
string|null
$root
= null
$rootAttributes
protected
array<string, mixed>
$rootAttributes
= []
$rootNS
protected
array<string|int, string>
$rootNS
= []
$validXml
protected
bool
$validXml
= false
$version
protected
string|null
$version
= null
Methods
__toString()
Convert XML to string.
public
__toString() : string
Return values
stringextract()
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
@contentdirectly (if exists). Default:false. - $attributes : bool = false
-
If true, get
@attributesdirectly (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>getConverter()
XML converter.
public
getConverter() : XmlConverter|null
Return values
XmlConverter|nullgetEncoding()
Encoding of XML.
public
getEncoding() : string|null
Return values
string|nullgetFilename()
Filename of XML file.
public
getFilename() : string|null
Return values
string|nullgetPath()
Path of XML file.
public
getPath() : string|null
Return values
string|nullgetRoot()
Value of root element.
public
getRoot() : string|null
Return values
string|nullgetRootAttribute()
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|nullisValidXml()
If XML is valid.
public
isValidXml() : bool
Return values
boolmake()
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
@contentkey, return only the value of@content. Default:true. - $failOnError : bool = true
-
Throw exception if XML is invalid. Default:
true.
Tags
Return values
selfparseAttributes()
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>|nullparseContent()
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
boolsearch()
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