Skip to main content

UriReferenceResolver

Struct UriReferenceResolver 

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

Source

pub fn new(doc: &'a Document<'a>) -> Self

Build a resolver with default ID attribute names (ID, Id, id).

Source

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".

Source

pub fn dereference( &self, uri: &str, ) -> Result<TransformData<'a>, TransformError>

Dereference a URI string to a TransformData.

§URI forms
URIResult
"" (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
otherErr(UnsupportedUri)
Source

pub fn has_id(&self, id: &str) -> bool

Check if an ID is registered in the resolver’s index.

Source

pub fn id_count(&self) -> usize

Get the number of registered IDs.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.