You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/9.0/converter/xml.md
+19-3Lines changed: 19 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,9 @@ title: Converting a CSV into a XML DOMDocument object
7
7
8
8
The `XMLConverter` converts a CSV records collection into a PHP `DOMDocument`.
9
9
10
+
<pclass="message-info">Starting with version <code>9.22.0</code>, support for
11
+
returning <code>\Dom\XmlDocument</code> instances is added</p>
12
+
10
13
## Settings
11
14
12
15
Prior to converting your records collection into XML, you may wish to configure the element and its associated attribute names. To do so, `XMLConverter` provides methods to set up these settings.
@@ -57,10 +60,23 @@ This method allow to apply a callback prior to converting your collection indivi
57
60
This callback allows you to specify how each item will be converted. The formatter should
58
61
return an associative array suitable for conversion.
59
62
63
+
### XMLConverter::xmlClass
64
+
65
+
<pclass="message-info">New feature introduced in version <code>9.22.0</code></p>
66
+
67
+
```php
68
+
public XMLConverter::xmlClass(string $xmlClass): self
69
+
```
70
+
71
+
This method allow to specify the return type when calling the `convert` method.
72
+
The accepted values are `DomDocument` or `Dom\XmlDocument` class names any other
73
+
value will trigger a `ValueError` from the API. To avoid BC break the default
74
+
value if this method is **NEVER** call is `DomDocument`.
75
+
60
76
## Conversion
61
77
62
78
```php
63
-
public XMLConverter::convert(iterable $records): DOMDocument
79
+
public XMLConverter::convert(iterable $records): DOMDocument|\Dom\XmlDocument
64
80
```
65
81
66
82
The `XMLConverter::convert` accepts an `iterable` which represents the records collection and returns a `DOMDocument` object.
<pclass="message-info">New feature introduced in version <code>9.3.0</code></p>
121
137
122
138
```php
123
-
public XMLConverter::import(iterable $records, DOMDocument $doc): DOMElement
139
+
public XMLConverter::import(iterable $records, DOMDocument|\Dom\XMLDocument $doc): DOMElement|\Dom\Element
124
140
```
125
141
126
142
Instead of converting your tabular data into a full XML document you can now import it into an already existing `DOMDocument` object.
@@ -129,7 +145,7 @@ To do so, you need to specify which document the data should be imported into us
129
145
This method takes two arguments:
130
146
131
147
- the tabular data as defined for the `XMLConverter::convert` method;
132
-
- a `DOMDocument` object to import the data into;
148
+
- a `DOMDocument`or a `\Dom\XmlDocument`object to import the data into;
133
149
134
150
Note that the resulting `DOMElement` is attached to the given `DOMDocument` object but not yet included in the document tree.
135
151
To include it, you still need to call a DOM insertion method like `appendChild` or `insertBefore` with a node that *is* currently in the document tree.
0 commit comments