Struct Node

Source
pub struct Node(/* private fields */);
Expand description

An xml node

Implementations§

Source§

impl Node

Source

pub fn new( name: &str, ns: Option<Namespace>, doc: &Document, ) -> Result<Self, ()>

Create a new node, bound to a given document.

Source

pub fn node_ptr(&self) -> xmlNodePtr

Immutably borrows the underlying libxml2 xmlNodePtr pointer

Source

pub fn node_ptr_mut(&mut self) -> Result<xmlNodePtr, String>

Mutably borrows the underlying libxml2 xmlNodePtr pointer Also protects against mutability conflicts at runtime.

Source

pub fn new_text(content: &str, doc: &Document) -> Result<Self, ()>

Create a new text node, bound to a given document

Source

pub fn mock(doc: &Document) -> Self

Create a mock node, used for a placeholder argument

Source

pub fn null() -> Self

Create a mock node, used for a placeholder argument

Source

pub fn to_hashable(&self) -> usize

libc::c_void isn’t hashable and cannot be made hashable

Source

pub fn get_next_sibling(&self) -> Option<Node>

Returns the next sibling if it exists

Source

pub fn get_prev_sibling(&self) -> Option<Node>

Returns the previous sibling if it exists

Source

pub fn get_first_child(&self) -> Option<Node>

Returns the first child if it exists

Source

pub fn get_last_child(&self) -> Option<Node>

Returns the last child if it exists

Source

pub fn get_next_element_sibling(&self) -> Option<Node>

Returns the next element sibling if it exists

Source

pub fn get_prev_element_sibling(&self) -> Option<Node>

Returns the previous element sibling if it exists

Source

pub fn get_first_element_child(&self) -> Option<Node>

Returns the first element child if it exists

Source

pub fn get_last_element_child(&self) -> Option<Node>

Returns the last element child if it exists

Source

pub fn get_child_nodes(&self) -> Vec<Node>

Returns all child nodes of the given node as a vector

Source

pub fn get_child_elements(&self) -> Vec<Node>

Returns all child elements of the given node as a vector

Source

pub fn get_parent(&self) -> Option<Node>

Returns the parent if it exists

Source

pub fn get_type(&self) -> Option<NodeType>

Get the node type

Source

pub fn add_prev_sibling( &mut self, new_sibling: &mut Node, ) -> Result<(), Box<dyn Error + Send + Sync>>

Add a previous sibling

Source

pub fn add_next_sibling( &mut self, new_sibling: &mut Node, ) -> Result<(), Box<dyn Error + Send + Sync>>

Add a next sibling

Source

pub fn is_text_node(&self) -> bool

Returns true if it is a text node

Source

pub fn is_element_node(&self) -> bool

Checks if the given node is an Element

Source

pub fn is_null(&self) -> bool

Checks if the underlying libxml2 pointer is NULL

Source

pub fn get_name(&self) -> String

Returns the name of the node (empty string if name pointer is NULL)

Source

pub fn set_name( &mut self, name: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>

Sets the name of this Node

Source

pub fn get_content(&self) -> String

Returns the content of the node (assumes UTF-8 XML document)

Source

pub fn set_content( &mut self, content: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>

Sets the text content of this Node

Source

pub fn get_property(&self, name: &str) -> Option<String>

Returns the value of property name

Source

pub fn get_property_ns(&self, name: &str, ns: &str) -> Option<String>

Returns the value of property name in namespace ns

Source

pub fn get_property_no_ns(&self, name: &str) -> Option<String>

Returns the value of property name with no namespace

Source

pub fn get_property_node(&self, name: &str) -> Option<Node>

Return an attribute as a Node struct of type AttributeNode

Source

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

Source

pub fn get_property_node_no_ns(&self, name: &str) -> Option<Node>

Return an attribute with no namespace as a Node of type AttributeNode

Source

pub fn has_property(&self, name: &str) -> bool

Check if a property has been defined, without allocating its value

Source

pub fn has_property_ns(&self, name: &str, ns: &str) -> bool

Check if property name in namespace ns exists

Source

pub fn has_property_no_ns(&self, name: &str) -> bool

Check if property name with no namespace exists

Source

pub fn has_attribute(&self, name: &str) -> bool

Alias for has_property

Source

pub fn has_attribute_ns(&self, name: &str, ns: &str) -> bool

Alias for has_property_ns

Source

pub fn has_attribute_no_ns(&self, name: &str) -> bool

Alias for has_property_no_ns

Source

pub fn set_property( &mut self, name: &str, value: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>

Sets the value of property name to value

Source

pub fn set_property_ns( &mut self, name: &str, value: &str, ns: &Namespace, ) -> Result<(), Box<dyn Error + Send + Sync>>

Sets a namespaced attribute

Source

pub fn remove_property( &mut self, name: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>

Removes the property of given name

Source

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)

Source

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

Source

pub fn get_attribute(&self, name: &str) -> Option<String>

Alias for get_property

Source

pub fn get_attribute_ns(&self, name: &str, ns: &str) -> Option<String>

Alias for get_property_ns

Source

pub fn get_attribute_no_ns(&self, name: &str) -> Option<String>

Alias for get_property_no_ns

Source

pub fn get_attribute_node(&self, name: &str) -> Option<Node>

Alias for get_property_node

Source

pub fn get_attribute_node_ns(&self, name: &str, ns: &str) -> Option<Node>

Alias for get_property_node_ns

Source

pub fn get_attribute_node_no_ns(&self, name: &str) -> Option<Node>

Alias for get_property_node_no_ns

Source

pub fn set_attribute( &mut self, name: &str, value: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>

Alias for set_property

Source

pub fn set_attribute_ns( &mut self, name: &str, value: &str, ns: &Namespace, ) -> Result<(), Box<dyn Error + Send + Sync>>

Alias for set_property_ns

Source

pub fn remove_attribute( &mut self, name: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>

Alias for remove_property

Source

pub fn remove_attribute_ns( &mut self, name: &str, ns: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>

Alias for remove_property_ns

Source

pub fn remove_attribute_no_ns( &mut self, name: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>

Alias for remove_property_no_ns

Source

pub fn get_properties(&self) -> HashMap<String, String>

Get a copy of the attributes of this node

Source

pub fn get_properties_ns(&self) -> HashMap<(String, Option<Namespace>), String>

Get a copy of this node’s attributes and their namespaces

Source

pub fn get_attributes(&self) -> HashMap<String, String>

Alias for get_properties

Source

pub fn get_attributes_ns(&self) -> HashMap<(String, Option<Namespace>), String>

Alias for get_properties_ns

Source

pub fn get_namespace(&self) -> Option<Namespace>

Gets the active namespace associated of this node

Source

pub fn get_namespaces(&self, doc: &Document) -> Vec<Namespace>

Gets a list of namespaces associated with this node

Source

pub fn get_namespace_declarations(&self) -> Vec<Namespace>

Get a list of namespaces declared with this node

Source

pub fn set_namespace( &mut self, namespace: &Namespace, ) -> Result<(), Box<dyn Error + Send + Sync>>

Sets a Namespace for the node

Source

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

Source

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

Source

pub fn recursively_remove_namespaces( &mut self, ) -> Result<(), Box<dyn Error + Send + Sync>>

Removes the namespaces of this Node and it’s children!

Source

pub fn get_class_names(&self) -> HashSet<String>

Get a set of class names from this node’s attributes

Source

pub fn add_child(&mut self, child: &mut Node) -> Result<(), String>

Creates a new Node as child to the self Node

Source

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

Source

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

Source

pub fn append_text( &mut self, content: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>

Append text to this Node

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.

Alias for unlink_node

Source

pub fn unbind_node(&mut self)

Alias for unlink_node

Source

pub fn unbind(&mut self)

Alias for unlink_node

Source

pub fn is_unlinked(&self) -> bool

Checks if node is marked as unlinked

Source

pub fn findnodes(&self, xpath: &str) -> Result<Vec<Node>, ()>

find nodes via xpath, at a specified node or the document root

Source

pub fn findvalues(&self, xpath: &str) -> Result<Vec<String>, ()>

find String values via xpath, at a specified node or the document root

Source

pub fn replace_child_node( &mut self, new: Node, old: Node, ) -> Result<Node, Box<dyn Error + Send + Sync>>

replace a self’s old child node with a new node in the same position borrowed from Perl’s XML::LibXML

Trait Implementations§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Node

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Node

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Node

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Generates a hash value from the node_ptr value.

1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Node

Source§

fn eq(&self, other: &Node) -> bool

Two nodes are considered equal, if they point to the same xmlNode.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Node

Auto Trait Implementations§

§

impl Freeze for Node

§

impl !RefUnwindSafe for Node

§

impl !Send for Node

§

impl !Sync for Node

§

impl Unpin for Node

§

impl !UnwindSafe for Node

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.