QNametypeno test imports ittype QName = { readonly ns: string; readonly local: string };A name with its namespace.
XML for the bodies of WebDAV, strict and bounded. The reader takes one document of elements, attributes, text, CDATA, comments and the five named references and the numeric ones, and refuses everything that a document may use to attack its reader: a document type (so no entity is ever declared or expanded and no external subset is read), a reference it does not know, a name of a prefix that is not declared, and a document larger, deeper or with more parts than the limits allow. The writer escapes every text and attribute and declares each namespace once on the root.
import { parseXml, writeXml, dav } from "./xml.ts";
const doc = parseXml('<D:propfind xmlns:D="DAV:"><D:allprop/></D:propfind>', { maxBytes: 1024, maxDepth: 8, maxNodes: 100 });
writeXml({ name: dav("multistatus"), attrs: [], children: [] }); // '<?xml version="1.0" encoding="utf-8"?>\n<D:multistatus xmlns:D="DAV:"/>'QNametypeno test imports ittype QName = { readonly ns: string; readonly local: string };A name with its namespace.
XmlAttrtypeno test imports ittype XmlAttr = { readonly name: string; readonly value: string };One attribute: a name without a namespace prefix of its own (xmlns declarations are not attributes here) and its value.
XmlElementtypetype XmlElement = { readonly kind: "element"; readonly name: QName; readonly attrs: readonly XmlAttr[]; readonly children: readonly XmlNode[] };An element: its name, attributes and children.
XmlTexttypeno test imports ittype XmlText = { readonly kind: "text"; readonly text: string };A piece of text.
XmlNodetypeno test imports ittype XmlNode = XmlElement | XmlText;What an element holds.
DAV_NSconstno test imports itconst DAV_NS: "DAV:"The namespace of WebDAV.
davconstconst dav: (local: string) => QNameA name in the namespace of WebDAV.
elfunctionfunction el(name: QName, children?: readonly (string | XmlNode)[], attrs?: readonly XmlAttr[]): XmlElementAn element, with children that are elements or texts.
XmlLimitstypetype XmlLimits = { readonly maxBytes: number; readonly maxDepth: number; readonly maxNodes: number };What the reader is allowed.
XmlProblemtypeno test imports ittype XmlProblem =
| { readonly kind: "too-large"; readonly bytes: number }
| { readonly kind: "too-deep"; readonly a… (483 characters)type XmlProblem =
| { readonly kind: "too-large"; readonly bytes: number }
| { readonly kind: "too-deep"; readonly at: number }
| { readonly kind: "too-many"; readonly at: number }
| { readonly kind: "doctype"; readonly at: number }
| { readonly kind: "reference"; readonly at: number; readonly text: string }
| { readonly kind: "namespace"; readonly at: number; readonly prefix: string }
| { readonly kind: "malformed"; readonly at: number; readonly message: string };Why a document is not read: a closed list.
describeXmlProblemfunctionfunction describeXmlProblem(p: XmlProblem): stringA problem in a sentence.
parseXmlfunctionfunction parseXml(text: string, limits: XmlLimits): Result<XmlElement, XmlProblem>One document, or why it is not read.
childElementsfunctionno test imports itfunction childElements(e: XmlElement): readonly XmlElement[]The child elements of an element, in order.
textOffunctionno test imports itfunction textOf(e: XmlElement): stringThe text an element holds below it, joined.
isNamedconstno test imports itconst isNamed: (e: XmlElement, ns: string, local: string) => booleanWhether an element has a name.
writeXmlfunctionfunction writeXml(root: XmlElement): stringOne element as XML, with the namespaces declared once on it: DAV: is D, the others are n1, n2.