pub struct NamespaceStack<'ns> { /* private fields */ }Expand description
A NamespaceStack is a use of a Namespace structure within a document; in general they form a pair, with the Namespace created first and a NamespaceStack following.
The stack consists of frames, which can be pushed and popped. Within a frame there are mappings between prefix strings and URI strings; there will be at most one mapping for each prefix within the frame. Different stack frames may map the same prefix differently, though.
A mapping for a prefix string is determined by finding that mapping in the topmost stack frame if possible; if there is no mapping in that frame, the next frame down is examined, and so on.
URI and prefix strings are stored within the Namespace structure, and are referred to by ’id’s in most of the API - as are mappings from prefix to URI.
A client of the NamespaceStack should add mappings to the NamespaceStack with a [NamespaceStack::add] operation, which returns an NSMap; it can look up mappings for a prefix string by resolving the prefix string to an ID with [NamespaceStack::find_prefix], and then finding the map using NamespaceStack::find_mapping.
A client can iterate through all the mappings using the iter() method.
§Example
use hml_rs::names::{NamespaceStack, Namespace};
let mut ns = Namespace::new(true);
let mut nst = NamespaceStack::new(&mut ns);
Implementations§
Source§impl<'ns> NamespaceStack<'ns>
impl<'ns> NamespaceStack<'ns>
Sourcepub fn new(namespaces: &'ns mut Namespace) -> Self
pub fn new(namespaces: &'ns mut Namespace) -> Self
Create a new NamespaceStack, mutably borrowing the Namespace for its lifetime
Sourcepub fn uses_xmlns(&self) -> bool
pub fn uses_xmlns(&self) -> bool
Return true if the Namespace was specified to use the XML namespace (at creation)
Sourcepub fn add_null_ns(&mut self)
pub fn add_null_ns(&mut self)
Add the null namespace
This is normally done at the creation of a NamespaceStack
Sourcepub fn add_default_xmls(&mut self)
pub fn add_default_xmls(&mut self)
Add the default XML namespaces to the stack frame
This is normally done at the creation of a NamespaceStack
Sourcepub fn push_frame(&mut self)
pub fn push_frame(&mut self)
Push a new stack frame on to the NamespaceStack
Sourcepub fn pop_frame(&mut self)
pub fn pop_frame(&mut self)
Pop the topmost stack frame from the NamespaceStack
Panics if the stack is empty
Sourcepub fn add_mapping_by_id(&mut self, map: NSMap)
pub fn add_mapping_by_id(&mut self, map: NSMap)
Add a mapping of NSPrefixId -> NSUriId to the topmost stack frame
Sourcepub fn add_mapping_by_id_if_unset(&mut self, map: NSMap) -> bool
pub fn add_mapping_by_id_if_unset(&mut self, map: NSMap) -> bool
Add a mapping if it does not exist in the topmost stack fram
Sourcepub fn find_mapping(&self, prefix_id: NSPrefixId) -> Option<NSUriId>
pub fn find_mapping(&self, prefix_id: NSPrefixId) -> Option<NSUriId>
Find a mapping of an NSPrefixId at the highest level of the stack that it exists
Returns None if there is no mapping on the stack at all
Sourcepub fn find_prefix_id(&mut self, prefix: &str) -> Option<NSPrefixId>
pub fn find_prefix_id(&mut self, prefix: &str) -> Option<NSPrefixId>
Find the NSPrefixId corresponding to a string within the underlying Namespace
Sourcepub fn iter_top_mappings(&self) -> NamespaceStackFrameIter<'_>
pub fn iter_top_mappings(&self) -> NamespaceStackFrameIter<'_>
Get a slice of the mappings of the topmost frame
Sourcepub fn borrow_mapping(&self, map: NSMap) -> (&str, &str)
pub fn borrow_mapping(&self, map: NSMap) -> (&str, &str)
Sourcepub fn prefix_str(&self, prefix: NSPrefixId) -> &str
pub fn prefix_str(&self, prefix: NSPrefixId) -> &str
Borrow the prefix corresponding to an NSPrefixId within the Namespace
Sourcepub fn add_ns(&mut self, prefix: &str, uri: &str) -> NSMap
pub fn add_ns(&mut self, prefix: &str, uri: &str) -> NSMap
Add a prefix -> URI mapping to the Namespace