pub struct Node(/* private fields */);Expand description
An xml node
Implementations§
Source§impl Node
impl Node
Sourcepub fn new(
name: &str,
ns: Option<Namespace>,
doc: &Document,
) -> Result<Self, ()>
pub fn new( name: &str, ns: Option<Namespace>, doc: &Document, ) -> Result<Self, ()>
Create a new node, bound to a given document.
Sourcepub fn node_ptr(&self) -> xmlNodePtr
pub fn node_ptr(&self) -> xmlNodePtr
Immutably borrows the underlying libxml2 xmlNodePtr pointer
Sourcepub fn node_ptr_mut(&mut self) -> Result<xmlNodePtr, String>
pub fn node_ptr_mut(&mut self) -> Result<xmlNodePtr, String>
Mutably borrows the underlying libxml2 xmlNodePtr pointer
Also protects against mutability conflicts at runtime.
Sourcepub fn new_text(content: &str, doc: &Document) -> Result<Self, ()>
pub fn new_text(content: &str, doc: &Document) -> Result<Self, ()>
Create a new text node, bound to a given document
Sourcepub fn to_hashable(&self) -> usize
pub fn to_hashable(&self) -> usize
libc::c_void isn’t hashable and cannot be made hashable
Sourcepub fn get_next_sibling(&self) -> Option<Node>
pub fn get_next_sibling(&self) -> Option<Node>
Returns the next sibling if it exists
Sourcepub fn get_prev_sibling(&self) -> Option<Node>
pub fn get_prev_sibling(&self) -> Option<Node>
Returns the previous sibling if it exists
Sourcepub fn get_first_child(&self) -> Option<Node>
pub fn get_first_child(&self) -> Option<Node>
Returns the first child if it exists
Sourcepub fn get_last_child(&self) -> Option<Node>
pub fn get_last_child(&self) -> Option<Node>
Returns the last child if it exists
Sourcepub fn get_next_element_sibling(&self) -> Option<Node>
pub fn get_next_element_sibling(&self) -> Option<Node>
Returns the next element sibling if it exists
Sourcepub fn get_prev_element_sibling(&self) -> Option<Node>
pub fn get_prev_element_sibling(&self) -> Option<Node>
Returns the previous element sibling if it exists
Sourcepub fn get_first_element_child(&self) -> Option<Node>
pub fn get_first_element_child(&self) -> Option<Node>
Returns the first element child if it exists
Sourcepub fn get_last_element_child(&self) -> Option<Node>
pub fn get_last_element_child(&self) -> Option<Node>
Returns the last element child if it exists
Sourcepub fn get_child_nodes(&self) -> Vec<Node>
pub fn get_child_nodes(&self) -> Vec<Node>
Returns all child nodes of the given node as a vector
Sourcepub fn get_child_elements(&self) -> Vec<Node>
pub fn get_child_elements(&self) -> Vec<Node>
Returns all child elements of the given node as a vector
Sourcepub fn get_parent(&self) -> Option<Node>
pub fn get_parent(&self) -> Option<Node>
Returns the parent if it exists
Sourcepub fn add_prev_sibling(
&mut self,
new_sibling: &mut Node,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn add_prev_sibling( &mut self, new_sibling: &mut Node, ) -> Result<(), Box<dyn Error + Send + Sync>>
Add a previous sibling
Sourcepub fn add_next_sibling(
&mut self,
new_sibling: &mut Node,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn add_next_sibling( &mut self, new_sibling: &mut Node, ) -> Result<(), Box<dyn Error + Send + Sync>>
Add a next sibling
Sourcepub fn is_text_node(&self) -> bool
pub fn is_text_node(&self) -> bool
Returns true if it is a text node
Sourcepub fn is_element_node(&self) -> bool
pub fn is_element_node(&self) -> bool
Checks if the given node is an Element
Sourcepub fn get_name(&self) -> String
pub fn get_name(&self) -> String
Returns the name of the node (empty string if name pointer is NULL)
Sourcepub fn set_name(
&mut self,
name: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn set_name( &mut self, name: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Sets the name of this Node
Sourcepub fn get_content(&self) -> String
pub fn get_content(&self) -> String
Returns the content of the node (assumes UTF-8 XML document)
Sourcepub fn set_content(
&mut self,
content: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn set_content( &mut self, content: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Sets the text content of this Node
Sourcepub fn get_property(&self, name: &str) -> Option<String>
pub fn get_property(&self, name: &str) -> Option<String>
Returns the value of property name
Sourcepub fn get_property_ns(&self, name: &str, ns: &str) -> Option<String>
pub fn get_property_ns(&self, name: &str, ns: &str) -> Option<String>
Returns the value of property name in namespace ns
Sourcepub fn get_property_no_ns(&self, name: &str) -> Option<String>
pub fn get_property_no_ns(&self, name: &str) -> Option<String>
Returns the value of property name with no namespace
Sourcepub fn get_property_node(&self, name: &str) -> Option<Node>
pub fn get_property_node(&self, name: &str) -> Option<Node>
Return an attribute as a Node struct of type AttributeNode
Sourcepub fn get_property_node_ns(&self, name: &str, ns: &str) -> Option<Node>
pub fn get_property_node_ns(&self, name: &str, ns: &str) -> Option<Node>
Return an attribute in a namespace ns as a Node of type AttributeNode
Sourcepub fn get_property_node_no_ns(&self, name: &str) -> Option<Node>
pub fn get_property_node_no_ns(&self, name: &str) -> Option<Node>
Return an attribute with no namespace as a Node of type AttributeNode
Sourcepub fn has_property(&self, name: &str) -> bool
pub fn has_property(&self, name: &str) -> bool
Check if a property has been defined, without allocating its value
Sourcepub fn has_property_ns(&self, name: &str, ns: &str) -> bool
pub fn has_property_ns(&self, name: &str, ns: &str) -> bool
Check if property name in namespace ns exists
Sourcepub fn has_property_no_ns(&self, name: &str) -> bool
pub fn has_property_no_ns(&self, name: &str) -> bool
Check if property name with no namespace exists
Sourcepub fn has_attribute(&self, name: &str) -> bool
pub fn has_attribute(&self, name: &str) -> bool
Alias for has_property
Sourcepub fn has_attribute_ns(&self, name: &str, ns: &str) -> bool
pub fn has_attribute_ns(&self, name: &str, ns: &str) -> bool
Alias for has_property_ns
Sourcepub fn has_attribute_no_ns(&self, name: &str) -> bool
pub fn has_attribute_no_ns(&self, name: &str) -> bool
Alias for has_property_no_ns
Sourcepub fn set_property(
&mut self,
name: &str,
value: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn set_property( &mut self, name: &str, value: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Sets the value of property name to value
Sourcepub fn set_property_ns(
&mut self,
name: &str,
value: &str,
ns: &Namespace,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn set_property_ns( &mut self, name: &str, value: &str, ns: &Namespace, ) -> Result<(), Box<dyn Error + Send + Sync>>
Sets a namespaced attribute
Sourcepub fn remove_property(
&mut self,
name: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn remove_property( &mut self, name: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Removes the property of given name
Sourcepub fn remove_property_ns(
&mut self,
name: &str,
ns: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn remove_property_ns( &mut self, name: &str, ns: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Removes the property of given name and namespace (ns)
Sourcepub fn remove_property_no_ns(
&mut self,
name: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn remove_property_no_ns( &mut self, name: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Removes the property of given name with no namespace
Sourcepub fn get_attribute(&self, name: &str) -> Option<String>
pub fn get_attribute(&self, name: &str) -> Option<String>
Alias for get_property
Sourcepub fn get_attribute_ns(&self, name: &str, ns: &str) -> Option<String>
pub fn get_attribute_ns(&self, name: &str, ns: &str) -> Option<String>
Alias for get_property_ns
Sourcepub fn get_attribute_no_ns(&self, name: &str) -> Option<String>
pub fn get_attribute_no_ns(&self, name: &str) -> Option<String>
Alias for get_property_no_ns
Sourcepub fn get_attribute_node(&self, name: &str) -> Option<Node>
pub fn get_attribute_node(&self, name: &str) -> Option<Node>
Alias for get_property_node
Sourcepub fn get_attribute_node_ns(&self, name: &str, ns: &str) -> Option<Node>
pub fn get_attribute_node_ns(&self, name: &str, ns: &str) -> Option<Node>
Alias for get_property_node_ns
Sourcepub fn get_attribute_node_no_ns(&self, name: &str) -> Option<Node>
pub fn get_attribute_node_no_ns(&self, name: &str) -> Option<Node>
Alias for get_property_node_no_ns
Sourcepub fn set_attribute(
&mut self,
name: &str,
value: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn set_attribute( &mut self, name: &str, value: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Alias for set_property
Sourcepub fn set_attribute_ns(
&mut self,
name: &str,
value: &str,
ns: &Namespace,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn set_attribute_ns( &mut self, name: &str, value: &str, ns: &Namespace, ) -> Result<(), Box<dyn Error + Send + Sync>>
Alias for set_property_ns
Sourcepub fn remove_attribute(
&mut self,
name: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn remove_attribute( &mut self, name: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Alias for remove_property
Sourcepub fn remove_attribute_ns(
&mut self,
name: &str,
ns: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn remove_attribute_ns( &mut self, name: &str, ns: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Alias for remove_property_ns
Sourcepub fn remove_attribute_no_ns(
&mut self,
name: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn remove_attribute_no_ns( &mut self, name: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Alias for remove_property_no_ns
Sourcepub fn get_properties(&self) -> HashMap<String, String>
pub fn get_properties(&self) -> HashMap<String, String>
Get a copy of the attributes of this node
Sourcepub fn get_properties_ns(&self) -> HashMap<(String, Option<Namespace>), String>
pub fn get_properties_ns(&self) -> HashMap<(String, Option<Namespace>), String>
Get a copy of this node’s attributes and their namespaces
Sourcepub fn get_attributes(&self) -> HashMap<String, String>
pub fn get_attributes(&self) -> HashMap<String, String>
Alias for get_properties
Sourcepub fn get_attributes_ns(&self) -> HashMap<(String, Option<Namespace>), String>
pub fn get_attributes_ns(&self) -> HashMap<(String, Option<Namespace>), String>
Alias for get_properties_ns
Sourcepub fn get_namespace(&self) -> Option<Namespace>
pub fn get_namespace(&self) -> Option<Namespace>
Gets the active namespace associated of this node
Sourcepub fn get_namespaces(&self, doc: &Document) -> Vec<Namespace>
pub fn get_namespaces(&self, doc: &Document) -> Vec<Namespace>
Gets a list of namespaces associated with this node
Sourcepub fn get_namespace_declarations(&self) -> Vec<Namespace>
pub fn get_namespace_declarations(&self) -> Vec<Namespace>
Get a list of namespaces declared with this node
Sourcepub fn set_namespace(
&mut self,
namespace: &Namespace,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn set_namespace( &mut self, namespace: &Namespace, ) -> Result<(), Box<dyn Error + Send + Sync>>
Sets a Namespace for the node
Sourcepub fn lookup_namespace_prefix(&self, href: &str) -> Option<String>
pub fn lookup_namespace_prefix(&self, href: &str) -> Option<String>
Looks up the prefix of a namespace from its URI, basedo around a given Node
Sourcepub fn lookup_namespace_uri(&self, prefix: &str) -> Option<String>
pub fn lookup_namespace_uri(&self, prefix: &str) -> Option<String>
Looks up the uri of a namespace from its prefix, basedo around a given Node
Sourcepub fn recursively_remove_namespaces(
&mut self,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn recursively_remove_namespaces( &mut self, ) -> Result<(), Box<dyn Error + Send + Sync>>
Removes the namespaces of this Node and it’s children!
Sourcepub fn get_class_names(&self) -> HashSet<String>
pub fn get_class_names(&self) -> HashSet<String>
Get a set of class names from this node’s attributes
Sourcepub fn add_child(&mut self, child: &mut Node) -> Result<(), String>
pub fn add_child(&mut self, child: &mut Node) -> Result<(), String>
Creates a new Node as child to the self Node
Sourcepub fn new_child(
&mut self,
ns: Option<Namespace>,
name: &str,
) -> Result<Node, Box<dyn Error + Send + Sync>>
pub fn new_child( &mut self, ns: Option<Namespace>, name: &str, ) -> Result<Node, Box<dyn Error + Send + Sync>>
Creates a new Node as child to the self Node
Sourcepub fn add_text_child(
&mut self,
ns: Option<Namespace>,
name: &str,
content: &str,
) -> Result<Node, Box<dyn Error + Send + Sync>>
pub fn add_text_child( &mut self, ns: Option<Namespace>, name: &str, content: &str, ) -> Result<Node, Box<dyn Error + Send + Sync>>
Adds a new text child, to this Node
Sourcepub fn append_text(
&mut self,
content: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn append_text( &mut self, content: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Append text to this Node
Sourcepub fn unlink_node(&mut self)
pub fn unlink_node(&mut self)
Unbinds the Node from its siblings and Parent, but not from the Document it belongs to. If the node is not inserted into the DOM afterwards, it will be lost after the program terminates. From a low level view, the unbound node is stripped from the context it is and inserted into a (hidden) document-fragment.
Sourcepub fn unbind_node(&mut self)
pub fn unbind_node(&mut self)
Alias for unlink_node
Sourcepub fn is_unlinked(&self) -> bool
pub fn is_unlinked(&self) -> bool
Checks if node is marked as unlinked
Sourcepub fn findnodes(&self, xpath: &str) -> Result<Vec<Node>, ()>
pub fn findnodes(&self, xpath: &str) -> Result<Vec<Node>, ()>
find nodes via xpath, at a specified node or the document root