Documentation

XmlUtils
in package

XMLUtils is a bunch of utility methods to XML operations.

This class contains static methods only and is not meant to be instantiated.

Tags
author

Fabien Potencier fabien@symfony.com

author

Martin Hasoň martin.hason@gmail.com

author

Ole Rößner ole@roessner.it

Table of Contents

convertDomElementToArray()  : mixed
Converts a \DOMElement object to a PHP array.
loadFile()  : DOMDocument
Loads an XML file.
parse()  : DOMDocument
Parses an XML string.
phpize()  : mixed
Converts an xml value to a PHP type.
getXmlErrors()  : mixed
__construct()  : mixed
This class should not be instantiated.
isOctal()  : bool

Methods

convertDomElementToArray()

Converts a \DOMElement object to a PHP array.

public static convertDomElementToArray(DOMElement $element[, bool $checkPrefix = true ]) : mixed

The following rules applies during the conversion:

  • Each tag is converted to a key value or an array if there is more than one "value"

  • The content of a tag is set under a "value" key (bar) if the tag also has some nested tags

  • The attributes are converted to keys ()

  • The nested-tags are converted to keys (bar)

Parameters
$element : DOMElement

A \DOMElement instance

$checkPrefix : bool = true

Check prefix in an element or an attribute name

Return values
mixed

loadFile()

Loads an XML file.

public static loadFile(string $file[, string|callable|null $schemaOrCallable = null ]) : DOMDocument
Parameters
$file : string

An XML file path

$schemaOrCallable : string|callable|null = null

An XSD schema file path, a callable, or null to disable validation

Tags
throws
InvalidArgumentException

When loading of XML file returns error

throws
XmlParsingException

When XML parsing returns any errors

throws
RuntimeException

When DOM extension is missing

Return values
DOMDocument

parse()

Parses an XML string.

public static parse(string $content[, string|callable|null $schemaOrCallable = null ]) : DOMDocument
Parameters
$content : string

An XML string

$schemaOrCallable : string|callable|null = null

An XSD schema file path, a callable, or null to disable validation

Tags
throws
XmlParsingException

When parsing of XML file returns error

throws
InvalidXmlException

When parsing of XML with schema or callable produces any errors unrelated to the XML parsing itself

throws
RuntimeException

When DOM extension is missing

Return values
DOMDocument

phpize()

Converts an xml value to a PHP type.

public static phpize(mixed $value) : mixed
Parameters
$value : mixed
Return values
mixed

getXmlErrors()

protected static getXmlErrors(bool $internalErrors) : mixed
Parameters
$internalErrors : bool
Return values
mixed

__construct()

This class should not be instantiated.

private __construct() : mixed
Return values
mixed

isOctal()

private static isOctal(string $str) : bool
Parameters
$str : string
Return values
bool

Search results