Skip to main content

NamespaceContext

Struct NamespaceContext 

Source
pub struct NamespaceContext<'a> { /* private fields */ }
Expand description

Scoped prefix-to-namespace mapping

Maintains a stack of scopes for namespace resolution during parsing. Each scope can add new prefix bindings that shadow outer scopes.

§Example

use xsd_schema::namespace::{NameTable, NamespaceContext};

let mut table = NameTable::new();
let mut ctx = NamespaceContext::new(&mut table);

// Root scope with XSD namespace
ctx.push_scope();
ctx.add_namespace("xs", "http://www.w3.org/2001/XMLSchema");

// Inner scope can shadow
ctx.push_scope();
ctx.add_namespace("xs", "http://different/namespace");

ctx.pop_scope(); // Back to original binding
ctx.pop_scope(); // Root scope removed

Implementations§

Source§

impl<'a> NamespaceContext<'a>

Source

pub fn new(name_table: &'a mut NameTable) -> Self

Create a new namespace context with standard bindings

Pre-binds:

  • xml -> http://www.w3.org/XML/1998/namespace
  • xmlns -> http://www.w3.org/2000/xmlns/
Source

pub fn name_table(&self) -> &NameTable

Get a reference to the name table

Source

pub fn name_table_mut(&mut self) -> &mut NameTable

Get a mutable reference to the name table

Source

pub fn push_scope(&mut self)

Push a new scope (called on element start)

Source

pub fn pop_scope(&mut self)

Pop the current scope (called on element end)

§Panics

Panics if there are no scopes to pop.

Source

pub fn add_namespace(&mut self, prefix: &str, uri: &str)

Add a namespace binding to the current scope

§Arguments
  • prefix - The prefix (empty string for default namespace)
  • uri - The namespace URI
Source

pub fn lookup_namespace(&self, prefix: &str) -> Option<NameId>

Look up namespace URI for a prefix string

Source

pub fn lookup_namespace_by_id(&self, prefix_id: NameId) -> Option<NameId>

Look up namespace URI for a prefix NameId

Source

pub fn default_namespace(&self) -> Option<NameId>

Get the default namespace (for unprefixed elements)

Source

pub fn set_default_namespace(&mut self, uri: Option<&str>)

Set the default namespace directly

Source

pub fn set_default_namespace_id(&mut self, ns: Option<NameId>)

Set the default namespace to an already-interned NameId.

Used by the parser to install a chameleon-adopted namespace on the root <xs:schema> scope (§4.2.3 clause 2.3): when an included schema has no targetNamespace and no explicit xmlns default, unqualified QName references inside it must resolve to the includer’s target namespace. Pre-setting the scope’s default namespace produces that resolution naturally during subsequent QName parsing.

Source

pub fn get_namespaces_in_scope( &self, scope_filter: NamespaceScope, ) -> Vec<(NameId, NameId)>

Get all namespace bindings in scope

§Arguments
  • scope_filter - Filter for which namespaces to include

Returns Vec of (prefix_id, namespace_id) pairs.

Source

pub fn depth(&self) -> usize

Get current scope depth

Source

pub fn snapshot(&self) -> NamespaceContextSnapshot

Create a snapshot of current namespace bindings

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for NamespaceContext<'a>

§

impl<'a> !Sync for NamespaceContext<'a>

§

impl<'a> !UnwindSafe for NamespaceContext<'a>

§

impl<'a> Freeze for NamespaceContext<'a>

§

impl<'a> Send for NamespaceContext<'a>

§

impl<'a> Unpin for NamespaceContext<'a>

§

impl<'a> UnsafeUnpin for NamespaceContext<'a>

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<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> ErasedDestructor for T
where T: 'static,

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> MaybeSendSync for T

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.