Skip to main content

Crate bpmnkit_xml

Crate bpmnkit_xml 

Source
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§

XmlSink
Receives the events of one document from scan_xml.

Functions§

decode_entities
Decodes &amp; &lt; &gt; &quot; &apos; 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
name without its prefix (bpmn:task → task).
parse_xml
Parses xml into an element tree.
scan_xml
Scans xml, reporting the root element and everything inside it to sink. Returns false when the document has no root element. Content after the root element is ignored.
serialize_xml
Writes element as a document with an XML declaration, two-space indentation and a trailing newline, byte-identical to TS’s serializeXml.
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.