docx-validate
    Preparing search index...

    Function decodeXmlBytes

    • Byte-level decoding for the DOM layer. @xmldom takes a JavaScript string, so a part stored as UTF-16 must be decoded from its ORIGINAL BYTES first โ€” reading it as UTF-8 (fs.readFile(file, "utf-8")) yields NUL-interleaved garbage that no parser can rescue.

      Encoding selection follows XML 1.0 ยง4.3.3: the byte order mark wins, then the encoding pseudo-attribute of the XML declaration. Only the three encodings OOXML parts actually use are supported โ€” UTF-8, UTF-16LE, UTF-16BE โ€” and anything else falls back to UTF-8 rather than guessing. The result carries no BOM and no leading whitespace, so callers can hand it straight to parseXml.

      A caller that writes the part back must use decodeXmlPart, which reports the encoding it found and refuses an encoding it cannot decode.

      Parameters

      • bytes: Uint8Array

      Returns string