XmlHelper
in package
Convert object to xml and back
Table of Contents
Methods
- Decode() : XmlNode
- Decodes an XML string into an XmlNode object.
- Encode() : string
- Encodes an object, string, or array into a string representation.
- ToObject() : object|string
- Converts an XML string or XmlNode object into an object or string representation.
Methods
Decode()
Decodes an XML string into an XmlNode object.
public
static Decode(string $xmlString) : XmlNode
This function takes an XML string and constructs an XmlNode object representing the parsed XML structure. The resulting object can be used to navigate and manipulate the XML data.
Parameters
- $xmlString : string
-
The XML string to be decoded.
Return values
XmlNode —An object representing the parsed XML structure.
Encode()
Encodes an object, string, or array into a string representation.
public
static Encode(XmlSerialized|string|array<string|int, mixed> $object[, string $tag = 'object' ]) : string
This function takes an input value (which can be an object, string, or array) and
converts it into a string representation. The resulting string format may be related
to XML serialization, as indicated by the optional $tag
parameter.
Parameters
- $object : XmlSerialized|string|array<string|int, mixed>
-
The input value to be encoded.
- $tag : string = 'object'
-
The optional tag name (default: 'object') for the encoded data.
Return values
string —The encoded string representation.
ToObject()
Converts an XML string or XmlNode object into an object or string representation.
public
static ToObject(string|XmlNode $xml) : object|string
This function takes either an XML string or an XmlNode object and constructs an object or string representation based on the input type. If an XmlNode object is provided, it is converted to an object. If an XML string is provided, it is returned as a string.
Parameters
- $xml : string|XmlNode
-
The XML string or XmlNode object to be converted.
Return values
object|string —The resulting object or string representation.