pub struct UriReferenceResolver<'a> { /* private fields */ }Expand description
Resolves same-document URI references against a parsed XML document.
Builds a HashMap<&str, Node> index on construction for O(1) fragment
lookups. Supports caller-provided ID attribute names (important for SAML
which uses ID rather than the xml:id mechanism).
§Example
use xml_sec::xmldsig::uri::UriReferenceResolver;
let xml = r#"<root><item ID="abc">content</item></root>"#;
let doc = roxmltree::Document::parse(xml)?;
let resolver = UriReferenceResolver::new(&doc);
assert!(resolver.has_id("abc"));
assert_eq!(resolver.id_count(), 1);Implementations§
Source§impl<'a> UriReferenceResolver<'a>
impl<'a> UriReferenceResolver<'a>
Sourcepub fn new(doc: &'a Document<'a>) -> Self
pub fn new(doc: &'a Document<'a>) -> Self
Build a resolver with default ID attribute names (ID, Id, id).
Sourcepub fn with_id_attrs(doc: &'a Document<'a>, extra_attrs: &[&str]) -> Self
pub fn with_id_attrs(doc: &'a Document<'a>, extra_attrs: &[&str]) -> Self
Build a resolver scanning additional ID attribute names beyond the defaults.
The defaults (ID, Id, id) are always included; extra_attrs
adds to them (does not replace). Pass an empty slice to use only defaults.
Attribute names are matched using roxmltree’s local-name view of
attributes: any namespace prefix is stripped before comparison. For
example, an attribute written as wsu:Id="..." in the XML is seen as
simply Id by roxmltree, so callers must pass "Id", not
"wsu:Id" or "{namespace}Id".
Sourcepub fn dereference(
&self,
uri: &str,
) -> Result<TransformData<'a>, TransformError>
pub fn dereference( &self, uri: &str, ) -> Result<TransformData<'a>, TransformError>
Dereference a URI string to a TransformData.
§URI forms
| URI | Result |
|---|---|
"" (empty) | Entire document, comments excluded |
"#foo" | Subtree rooted at element with ID foo |
"#xpointer(/)" | Entire document, comments included |
"#xpointer(id('foo'))" | Subtree rooted at element with ID foo |
| other | Err(UnsupportedUri) |