XmlResponseFormatter
API reference › yii › web › XmlResponseFormatter
XmlResponseFormatter formats the given data into an XML response content.
It is used by Response to format response data.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$behaviors read-only | array<yii\<static>> | List of behaviors attached to this component. | yii\ |
$contentType | string | The Content-Type header for the response Default: 'application/xml'. | XmlResponseFormatter |
$encoding | string| | The XML encoding. Default: null. | XmlResponseFormatter |
$itemTag | string | The name of the elements that represent the array elements with numeric keys. Default: 'item'. | XmlResponseFormatter |
$objectTagToLowercase | bool | If true, converts object tags to lowercase, $useObjectTags must be enabled Default: false. Available since 2.0.43. | XmlResponseFormatter |
$rootTag | string| | The name of the root element. Default: 'response'. | XmlResponseFormatter |
$useObjectTags | bool | If object class names should be used as tag names Default: true. Available since 2.0.11. | XmlResponseFormatter |
$useTraversableAsArray | bool | Whether to interpret objects implementing the Traversable interface as arrays. Default: true. Available since 2.0.7. | XmlResponseFormatter |
$version | string | The XML version Default: '1.0'. | XmlResponseFormatter |
$dom protected | DOMDocument | The XML document, serves as the root of the document tree Default: null. Available since 2.0.43. | XmlResponseFormatter |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__clone() | This method is called after the object is created by cloning an existing one. | yii\ |
__get() | Returns the value of a component property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets the value of a component property. | yii\ |
__unset() | Sets a component property to be null. | yii\ |
attachBehavior() | Attaches a behavior to this component. | yii\ |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\ |
behaviors() | Returns a list of behaviors that this component should behave as. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
detachBehavior() | Detaches a behavior from the component. | yii\ |
detachBehaviors() | Detaches all behaviors from the component. | yii\ |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\ |
format() | Formats the specified response. | XmlResponseFormatter |
getBehavior() | Returns the named behavior object. | yii\ |
getBehaviors() | Returns all behaviors attached to this component. | yii\ |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\ |
hasMethod() | Returns a value indicating whether a method is defined. | yii\ |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\ |
init() | Initializes the object. | yii\ |
off() | Detaches an existing event handler from this component. | yii\ |
on() | Attaches an event handler to an event. | yii\ |
trigger() | Triggers an event. | yii\ |
buildXml() protected | Recursively adds data to XML document. | XmlResponseFormatter |
formatScalarValue() protected | Formats scalar value to use in XML text node. | XmlResponseFormatter |
getValidXmlElementName() protected | Returns element name ready to be used in DOMElement if name is not empty, is not int and is valid. | XmlResponseFormatter |
isValidXmlName() protected | Checks if name is valid to be used in XML. | XmlResponseFormatter |
Property details
Section titled “Property details”$encoding
Section titled “$encoding ”public string|null $encoding = nullThe XML encoding.
If not set, it will use the value of Response::$charset.
$rootTag
Section titled “$rootTag ”public string|string[]|null|false $rootTag = 'response'The name of the root element.
If set to false, null or is empty then no root tag should be added.
Since 2.0.44 URI namespace could be specified by passing [namespace, tag name] array.
$useTraversableAsArray
Section titled “$useTraversableAsArray ”public bool $useTraversableAsArray = trueWhether to interpret objects implementing the Traversable interface as arrays.
Defaults to true.
Since
2.0.7
Method details
Section titled “Method details”format()
Section titled “format() ”public function format(yii\web\Response $response): mixedFormats the specified response.
buildXml()
Section titled “buildXml() ”protected function buildXml(DOMElement|DOMDocument $element, mixed $data): mixedRecursively adds data to XML document.
Parameters
| Parameter | Type | Description |
|---|---|---|
$element | DOMElement|DOMDocument | Current element |
$data | mixed | Content of the current element |
Returns
mixed
formatScalarValue()
Section titled “formatScalarValue() ”protected function formatScalarValue(int|string|bool|float $value): stringFormats scalar value to use in XML text node.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | int| | A scalar value. |
Returns
string: String representation of the value.
Since
2.0.11
getValidXmlElementName()
Section titled “getValidXmlElementName() ”protected function getValidXmlElementName(mixed $name): stringReturns element name ready to be used in DOMElement if name is not empty, is not int and is valid.
Falls back to $itemTag otherwise.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | mixed | The original name |
Returns
string
Since
2.0.12
isValidXmlName()
Section titled “isValidXmlName() ”protected function isValidXmlName(mixed $name): boolChecks if name is valid to be used in XML.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | mixed | The name to test |
Returns
bool
Since
2.0.12
See also