XMLBuilder class provides the foundation for building XML documents. It’s extended by ArrayExporter and ViewExporter.
Constructor
The encoding to use for the XML document.
The XML version to use.
You typically don’t use XMLBuilder directly. Use
XML::export() or XML::exportView() instead.Configuration Methods
version()
Set the XML version.The XML version string.
Returns the builder instance for chaining.
encoding()
Set the XML encoding.The character encoding (e.g., UTF-8, ISO-8859-1).
Returns the builder instance for chaining.
rootTag()
Set the name of the root XML tag.The name for the root tag.
Returns the builder instance for chaining.
setRootTag()
Set or disable the root tag.The root tag name, or
false to disable the root tag.Returns the builder instance for chaining.
disableRootTag()
Disable the root tag wrapper.Returns the builder instance for chaining.
itemName()
Set the default name for items without explicit keys.The default name for array items without keys.
Returns the builder instance for chaining.
Data Methods
data()
Set the data to be exported.The array data to convert to XML.
Returns the builder instance for chaining.
forceItemName()
Force usage of the item name instead of auto-generating names based on the root tag.Returns the builder instance for chaining.
Protected Methods
These methods are used internally by exporters but can be useful to understand the XML generation process.getProlog()
Generate the XML prolog (declaration).Returns the XML prolog string.
openRootTag()
Generate the opening root tag.Returns the opening tag or empty string if root tag is disabled.
closeRootTag()
Generate the closing root tag.Returns the closing tag or empty string if root tag is disabled.
getRootTag()
Get the current root tag name.Returns the root tag name (defaults to ‘root’).
getFieldName()
Generate the name for top-level tags.The field name or numeric index.
Returns the generated field name.
generateFieldName()
Generate field names for numeric keys.The parent field name.
Returns the singular form of the field name or the configured item name.
Magic Methods
__call()
Handle dynamic setters for configuration properties.The method name (must be one of: version, rootTag, encoding, itemName).
The method arguments (exactly one argument required).
Returns the builder instance for chaining.
Complete Example
In practice, use
XML::export() which returns an ArrayExporter that extends XMLBuilder with additional export functionality.Inheritance
The following classes extend XMLBuilder:ArrayExporter- Exports arrays to XMLViewExporter- Exports Blade views to XML