Skip to content

Documentation / @einvoice-ts/parser / parse

Function: parse() ​

parse(xml): ParseResult<UncheckedDocument>

Defined in: parse.ts:192

Parses a UBL invoice or credit note, whichever the document element says it is.

Parameters ​

xml ​

string

The document, as text.

Returns ​

ParseResult<UncheckedDocument>

The model, the structural diagnostics and whether any of them is fatal.

Throws ​

When the document is not well-formed XML, or its elements nest deeper than 1,000 levels (the document element is the first).

Throws ​

When the document element is neither a UBL Invoice nor a UBL CreditNote.

Example ​

ts
import { parse } from '@einvoice-ts/parser';

const { document, ok } = parse(xml);
if (document.kind === 'Invoice') console.log(document.invoiceLine?.length);

MIT licensed. Specification material belongs to OpenPeppol, CEN and OASIS (see NOTICE). Peppol is a trademark of OpenPeppol AISBL; this project is not affiliated with it.