Expand description
The small, dependency-free XML reader the hl7-2 crates share.
The name says what it is for. Nothing here is HL7-specific, but the
crate is scoped to serve hl7-2-soap, hl7-2-from-xml-into-er7 and
hl7-2-from-xsd-into-json-dictionary, and every trade-off below is
chosen for the documents those read.
It is not a general-purpose parser and does not try to be. It reads the
subset that carries meaning in a data document — elements, attributes,
text, and nesting — and skips the rest: comments, processing
instructions, a DOCTYPE, and the XML declaration. There is no
validation, no schema, no DTD, no namespace resolution, and no streaming.
What it is for: reading a document produced by a system you are talking to, where you know which elements you want and simply need them out. A SOAP envelope, an XML Schema, an HL7 v2.xml message. For anything where the document is untrusted, unbounded, or genuinely unknown, use a real parser.
let root = hl7_2_xml_lite_helper::parse(
r#"<order id="7"><item qty="2">widget</item></order>"#,
)?;
assert_eq!(root.attribute("id"), Some("7"));
let item = root.child("item").unwrap();
assert_eq!(item.attribute("qty"), Some("2"));
assert_eq!(item.text, "widget");§Namespace prefixes are ignored, not resolved
Elements and attributes are matched on their local name, so
soapenv:Body, soap:Body, SOAP-ENV:Body and Body are the same
element. This is the single most important thing to understand about
this crate, and it is a deliberate trade: the prefix is chosen by
whoever serialized the document, and code that insists on one prefix
rejects valid documents from every other tool. A document that binds the
same prefix to two namespaces, or relies on the distinction between two
namespaces that happen to use the same local names, will be misread.
Reach for a namespace-aware parser there.
See spec/index.md for the exact rules (source of truth).
Structs§
- Element
- One element: its name, attributes, text, and children.
Enums§
- Error
- Why a document could not be read.
Functions§
- escape
- Escape text for element content or an attribute value.
- local_
name - The local part of a possibly-prefixed XML name.
- parse
- Parse a document and return its root element.