Skip to content

Commit

Permalink
* Ability to provide custom dtd to serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
mathielen committed Jan 28, 2025
1 parent 6855c48 commit befb3f0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/CXml/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
{
public const DOC_TYPE_VERSION = '1.2.063';

private function __construct(private SerializerInterface $jmsSerializer)
{
}
private function __construct(
private SerializerInterface $jmsSerializer,
private string $dtdUri = 'http://xml.cxml.org/schemas/cXML/' . self::DOC_TYPE_VERSION . '/cXML.dtd'
)
{}

public static function create(): self
{
Expand Down Expand Up @@ -71,11 +73,11 @@ public function deserialize(string $xml): CXml
return $this->jmsSerializer->deserialize($xml, CXml::class, 'xml');
}

public function serialize(CXml $cxml, string $docTypeVersion = self::DOC_TYPE_VERSION): string
public function serialize(CXml $cxml): string
{
$xml = $this->jmsSerializer->serialize($cxml, 'xml');

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

// add doctype, as it is mandatory in cXML
Expand Down

0 comments on commit befb3f0

Please sign in to comment.