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 removedImplementations§
Source§impl<'a> NamespaceContext<'a>
impl<'a> NamespaceContext<'a>
Sourcepub fn new(name_table: &'a mut NameTable) -> Self
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/
Sourcepub fn name_table(&self) -> &NameTable
pub fn name_table(&self) -> &NameTable
Get a reference to the name table
Sourcepub fn name_table_mut(&mut self) -> &mut NameTable
pub fn name_table_mut(&mut self) -> &mut NameTable
Get a mutable reference to the name table
Sourcepub fn push_scope(&mut self)
pub fn push_scope(&mut self)
Push a new scope (called on element start)
Sourcepub fn add_namespace(&mut self, prefix: &str, uri: &str)
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
Sourcepub fn lookup_namespace(&self, prefix: &str) -> Option<NameId>
pub fn lookup_namespace(&self, prefix: &str) -> Option<NameId>
Look up namespace URI for a prefix string
Sourcepub fn lookup_namespace_by_id(&self, prefix_id: NameId) -> Option<NameId>
pub fn lookup_namespace_by_id(&self, prefix_id: NameId) -> Option<NameId>
Look up namespace URI for a prefix NameId
Sourcepub fn default_namespace(&self) -> Option<NameId>
pub fn default_namespace(&self) -> Option<NameId>
Get the default namespace (for unprefixed elements)
Sourcepub fn set_default_namespace(&mut self, uri: Option<&str>)
pub fn set_default_namespace(&mut self, uri: Option<&str>)
Set the default namespace directly
Sourcepub fn set_default_namespace_id(&mut self, ns: Option<NameId>)
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.
Sourcepub fn get_namespaces_in_scope(
&self,
scope_filter: NamespaceScope,
) -> Vec<(NameId, NameId)>
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.
Sourcepub fn snapshot(&self) -> NamespaceContextSnapshot
pub fn snapshot(&self) -> NamespaceContextSnapshot
Create a snapshot of current namespace bindings