Skip to content

Commit befb3f0

Browse files
committed
* Ability to provide custom dtd to serializer
1 parent 6855c48 commit befb3f0

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/CXml/Serializer.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
{
3131
public const DOC_TYPE_VERSION = '1.2.063';
3232

33-
private function __construct(private SerializerInterface $jmsSerializer)
34-
{
35-
}
33+
private function __construct(
34+
private SerializerInterface $jmsSerializer,
35+
private string $dtdUri = 'http://xml.cxml.org/schemas/cXML/' . self::DOC_TYPE_VERSION . '/cXML.dtd'
36+
)
37+
{}
3638

3739
public static function create(): self
3840
{
@@ -71,11 +73,11 @@ public function deserialize(string $xml): CXml
7173
return $this->jmsSerializer->deserialize($xml, CXml::class, 'xml');
7274
}
7375

74-
public function serialize(CXml $cxml, string $docTypeVersion = self::DOC_TYPE_VERSION): string
76+
public function serialize(CXml $cxml): string
7577
{
7678
$xml = $this->jmsSerializer->serialize($cxml, 'xml');
7779

78-
$docType = '<!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/' . $docTypeVersion . '/cXML.dtd">';
80+
$docType = '<!DOCTYPE cXML SYSTEM "'.$this->dtdUri.'">'."\n";
7981
$xmlPrefix = '<?xml version="1.0" encoding="UTF-8"?>';
8082

8183
// add doctype, as it is mandatory in cXML

0 commit comments

Comments
 (0)