facet-xml-node 0.44.0

Raw XML node types for facet-xml - represent arbitrary XML without a schema
Documentation

facet-xml-node

crates.io documentation MIT/Apache-2.0 licensed Discord

Raw XML node types—represent arbitrary XML without a schema.

Overview

This crate provides generic XML types (Element, Content) that can represent any XML document without needing predefined Rust structs. It's useful when you need to parse XML dynamically or work with XML of unknown structure.

Types

Element

Captures any XML element with its tag name, attributes, and children:

use facet_xml_node::Element;

let xml = r#"<item id="42" status="active">Hello <b>world</b></item>"#;
let element: Element = facet_xml::from_str(xml)?;

assert_eq!(element.tag, "item");
assert_eq!(element.attrs.get("id"), Some(&"42".to_string()));

Content

Represents either text or a child element:

use facet_xml_node::{Element, Content};

for child in &element.children {
    match child {
        Content::Text(t) => println!("Text: {}", t),
        Content::Element(e) => println!("Element: <{}>", e.tag),
    }
}

Use Cases

  • Parsing XML of unknown or variable structure
  • Building XML transformers or validators
  • Bridging between typed and untyped XML representations
  • Testing and debugging XML serialization

Comparison

Approach Use Case
Typed structs with #[derive(Facet)] Known XML schema, compile-time safety
facet-xml-node::Element Unknown/dynamic XML, runtime flexibility

Part of the Facet Ecosystem

This crate is part of the facet ecosystem, providing reflection for Rust.

License

Licensed under either of:

at your option.