Skip to main content
Version: v0.0.3

Function: serializeCcda()

serializeCcda(doc): string

Serialize a parsed CcdaDocument back to spec-clean C-CDA XML.

The output is the faithful re-emission of the document the parser read, no silent loss of unmodeled content, with a guaranteed XML declaration. Serialization is a fixed point: parseCcda(serializeCcda(doc)) re-serializes to the identical string. Equivalent to doc.toString().

Parameters

doc

CcdaDocument

A document produced by parseCcda.

Returns

string

The spec-clean XML text.

Throws

If doc was hand-constructed (neither produced by parseCcda nor by buildCcda) and therefore retains no source document to emit. To construct a document from scratch, use buildCcda, whose result is the parse of the XML it emitted and so serializes normally.

Example

import { parseCcda, serializeCcda } from "@cosyte/ccda";
const doc = parseCcda(xml);
const xmlOut = serializeCcda(doc); // spec-clean, declaration-prefixed