diff --git a/docs/9.0/converter/xml.md b/docs/9.0/converter/xml.md index 54b171f4..33ee770a 100644 --- a/docs/9.0/converter/xml.md +++ b/docs/9.0/converter/xml.md @@ -104,15 +104,24 @@ echo htmlentities($dom->saveXML());

If needed you can use the CharsetConverter object to correctly encode your CSV records before conversion.

-## Importing into a DOMDocument +## Import -Starting with version 9.3.0 you can now import the tabular data into an already existing `DOMDocument` object. Do to so you need to use the newly added method `XMLConverter::import`. -This methods takes two arguments: +

New feature introduced in version 9.3.0

+ +~~~php +public XMLConverter::import(iterable $records, DOMDocument $doc): DOMElement +~~~ + +Instead of converting your tabular data into a full XML document you can now import it into an already existing `DOMDocument` object. +Do to so you need to specify which document the data should be imported into using the `XMLConverter::import` method. + +This method takes two arguments: - the tabular data as defined for the `XMLConverter::convert` method; - a `DOMDocument` object to import the data into. - Of note the resulting DOMElement is attached to the given DOMDocument object but still need to be made visible by using a DOM insertion method like `appendChild` or `insertBefore`. + Of note the resulting `DOMElement` is attached to the given `DOMDocument` object but not yet included in the document tree. + 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. ~~~php use League\Csv\XMLConverter; @@ -123,7 +132,7 @@ This methods takes two arguments: $csv->setDelimiter(';'); $csv->setHeaderOffset(0); - $stmt = (new Statement()) + $stmt = (new Statement())` ->where(function (array $record) { return 'Anaïs' === $record['prenoms']; }) @@ -140,6 +149,8 @@ This methods takes two arguments: $records = $stmt->process($csv); $dom = new DOMDocument('1.0'); + $dom->loadXML('
My CSV Document
'); + $data = $converter->import($records, $dom); $dom->appendChild($data); $dom->formatOutput = true; @@ -148,18 +159,23 @@ This methods takes two arguments: echo '
', PHP_EOL;
  echo htmlentities($dom->saveXML());
  // 
- // 
- //   
- //     Anaïs
- //     137
- //     F
- //     2004
- //   
- //   
- //     Anaïs
- //     124
- //     F
- //     2005
- //   
- // 
+ // 
+ //   
+ // My CSV Document + //
+ // + // + // Anaïs + // 137 + // F + // 2004 + // + // + // Anaïs + // 124 + // F + // 2005 + // + // + //
~~~