Skip to content

Commit df8476c

Browse files
committed
Add XMLSerializer->appendToWriter()
1 parent 3754561 commit df8476c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/XMLSerializer.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace TheSeer\Tokenizer;
33

44
use DOMDocument;
5+
use XMLWriter;
56

67
class XMLSerializer {
78

@@ -32,6 +33,13 @@ public function toXML(TokenCollection $tokens): string {
3233
$writer = new \XMLWriter();
3334
$writer->openMemory();
3435
$writer->setIndent(true);
36+
37+
$this->appendToWriter($writer, $tokens);
38+
39+
return $writer->outputMemory();
40+
}
41+
42+
public function appendToWriter(XMLWriter $writer, TokenCollection $tokens): void {
3543
$writer->startDocument();
3644
$writer->startElement('source');
3745
$writer->writeAttribute('xmlns', $this->xmlns->asString());
@@ -68,7 +76,5 @@ public function toXML(TokenCollection $tokens): string {
6876

6977
$writer->endElement();
7078
$writer->endDocument();
71-
72-
return $writer->outputMemory();
7379
}
7480
}

0 commit comments

Comments
 (0)