Expand description
XML reading and writing with the fidelity @bpmnkit/core (packages/core/src/xml/xml-parser.ts)
has: qualified names keep their prefixes, attributes keep their source order, and nothing is
namespace-resolved, so unknown content can be written back as it was read.
Tokenising is done by quick-xml (borrowed events, builds for wasm32-unknown-unknown, and
already in reebe’s dependency tree). What the TS scanner decides itself is decided here too:
entity decoding (the five predefined entities and character references; anything else is kept
as written), CDATA kept raw, comments and processing instructions dropped, text concatenated
per element, and everything after the root element ignored.
use bpmnkit_xml::{parse_xml, serialize_xml};
let root = parse_xml(r#"<a:root xmlns:a="urn:x" b="1"><a:child>t</a:child></a:root>"#).unwrap();
assert_eq!(root.name, "a:root"); // prefixes are kept, not resolved
assert_eq!(root.local_name(), "root");
assert_eq!(root.attr("b"), Some("1"));
assert!(serialize_xml(&root).contains("<a:child>t</a:child>"));Structs§
- XmlElement
- An element with namespace prefixes preserved. The JSON shape matches TS’s
XmlElement. - XmlError
Enums§
- Visit
- What a sink wants the scanner to do with an element after its start tag.
Traits§
Functions§
- decode_
entities - Decodes
& < > " 'and numeric character references. Other&...;sequences are left as written, as in TS. - escape_
attr - Escapes a value for use between double quotes, including the whitespace an XML parser would normalise.
- escape_
text - Escapes a value for use as character data.
- local_
name namewithout its prefix (bpmn:task→task).- parse_
xml - Parses
xmlinto an element tree. - scan_
xml - Scans
xml, reporting the root element and everything inside it tosink. Returns false when the document has no root element. Content after the root element is ignored. - serialize_
xml - Writes
elementas a document with an XML declaration, two-space indentation and a trailing newline, byte-identical to TS’sserializeXml. - write_
element - Writes one element at
depth, ending with a newline.
Type Aliases§
- Attrs
- Attributes in source order. Qualified keys (
xsi:type) are kept as written.