Skip to main content
Version: v0.0.3

Function: parseSecureXml()

parseSecureXml(raw, limits, emit): Document

Strip a leading UTF-8 BOM and run the pre-parse safety gauntlet (size, DTD/DOCTYPE, entity-reference cap), then build a DOM with a hardened @xmldom/xmldom DOMParser, then enforce the depth / node-count caps on the constructed tree. Returns the root Document. Emits ENCODING_BOM_STRIPPED via emit when a BOM was removed.

Throws a CcdaParseError carrying a PHI-free CcdaPosition for any safety violation or malformed XML, never returns a partially-built document.

Parameters

raw

string

limits

ResolvedLimits

emit

(warning) => void

Returns

Document

Example

import { parseSecureXml, resolveLimits } from "@cosyte/ccda";
const doc = parseSecureXml("<ClinicalDocument/>", resolveLimits(), () => {});
console.log(doc.documentElement?.localName); // "ClinicalDocument"