pub struct XmlDocument { /* private fields */ }Expand description
An XML document.
The document owns all nodes and provides methods for traversal and manipulation. It uses a flat vector storage with indices for efficient memory usage and cache locality.
Implementations§
Source§impl XmlDocument
impl XmlDocument
Sourcepub fn document_node(&self) -> XmlNode
pub fn document_node(&self) -> XmlNode
Creates a document node reference.
Sourcepub fn get_root_element(&self) -> Result<XmlNode>
pub fn get_root_element(&self) -> Result<XmlNode>
Returns the root element node.
Sourcepub fn get_root_element_ro(&self) -> Result<XmlRoNode>
pub fn get_root_element_ro(&self) -> Result<XmlRoNode>
Returns the root element as a read-only node.
Sourcepub fn namespace_resolver(&self) -> Arc<RwLock<NamespaceResolver>>
pub fn namespace_resolver(&self) -> Arc<RwLock<NamespaceResolver>>
Returns the namespace resolver for this document.
Sourcepub fn register_namespace(&self, prefix: &str, uri: &str)
pub fn register_namespace(&self, prefix: &str, uri: &str)
Registers a namespace binding for XPath evaluation.
Sourcepub fn register_namespaces<I, S1, S2>(&self, iter: I)
pub fn register_namespaces<I, S1, S2>(&self, iter: I)
Registers multiple namespace bindings at once.
§Example
use fastxml::parse;
let xml = "<root><child/></root>";
let doc = parse(xml).unwrap();
doc.register_namespaces([
("gml", "http://www.opengis.net/gml"),
("bldg", "http://www.opengis.net/citygml/building/2.0"),
]);
let ns = doc.namespaces();
assert!(ns.contains_key("gml"));
assert!(ns.contains_key("bldg"));Sourcepub fn namespaces(&self) -> HashMap<String, String>
pub fn namespaces(&self) -> HashMap<String, String>
Returns all namespace bindings as a map of prefix -> URI.
This includes namespaces declared in the document and any manually registered namespaces.
§Example
use fastxml::parse;
let xml = r#"<root xmlns:gml="http://www.opengis.net/gml"
xmlns:bldg="http://www.opengis.net/citygml/building/2.0">
<gml:name>Test</gml:name>
</root>"#;
let doc = parse(xml).unwrap();
let namespaces = doc.namespaces();
assert_eq!(namespaces.get("gml"), Some(&"http://www.opengis.net/gml".to_string()));
assert_eq!(namespaces.get("bldg"), Some(&"http://www.opengis.net/citygml/building/2.0".to_string()));Sourcepub fn get_node_ro(&self, id: NodeId) -> Option<XmlRoNode>
pub fn get_node_ro(&self, id: NodeId) -> Option<XmlRoNode>
Gets a read-only node by ID.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Returns the total number of nodes in the document.
Sourcepub fn create_attribute_node(&self, name: &str, value: &str) -> XmlNode
pub fn create_attribute_node(&self, name: &str, value: &str) -> XmlNode
Creates a pseudo-attribute node for XPath evaluation.
These nodes are added to the document’s node list and can be used in XPath results. They store the attribute name and value.
Sourcepub fn create_namespace_node(&self, prefix: &str, uri: &str) -> XmlNode
pub fn create_namespace_node(&self, prefix: &str, uri: &str) -> XmlNode
Creates a pseudo-namespace node for XPath evaluation.
These nodes are added to the document’s node list and can be used in XPath results. They store the namespace prefix and URI.
Trait Implementations§
Source§impl Clone for XmlDocument
impl Clone for XmlDocument
Source§fn clone(&self) -> XmlDocument
fn clone(&self) -> XmlDocument
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more