pub trait Node:
Clone
+ PartialEq
+ Debug {
type NodeIterator: Iterator<Item = Self>;
Show 57 methods
// Required methods
fn new_document() -> Self;
fn node_type(&self) -> NodeType;
fn name(&self) -> Option<QName>;
fn value(&self) -> Rc<Value>;
fn to_qname(&self, name: impl AsRef<str>) -> Result<QName, Error>;
fn to_prefixed_name(&self) -> String;
fn to_namespace_prefix(
&self,
nsuri: &NamespaceUri,
) -> Result<Option<NamespacePrefix>, Error>;
fn to_namespace_uri(
&self,
prefix: &Option<NamespacePrefix>,
) -> Result<NamespaceUri, Error>;
fn as_namespace_prefix(&self) -> Result<Option<&NamespacePrefix>, Error>;
fn as_namespace_uri(&self) -> Result<&NamespaceUri, Error>;
fn is_in_scope(&self) -> bool;
fn get_id(&self) -> String;
fn to_string(&self) -> String;
fn to_xml(&self) -> String;
fn to_xml_with_options(&self, od: &OutputDefinition) -> String;
fn is_same(&self, other: &Self) -> bool;
fn is_attached(&self) -> bool;
fn document_order(&self) -> Vec<usize>;
fn cmp_document_order(&self, other: &Self) -> Ordering;
fn is_unattached(&self) -> bool;
fn is_id(&self) -> bool;
fn is_idrefs(&self) -> bool;
fn child_iter(&self) -> Self::NodeIterator;
fn ancestor_iter(&self) -> Self::NodeIterator;
fn owner_document(&self) -> Self;
fn descend_iter(&self) -> Self::NodeIterator;
fn next_iter(&self) -> Self::NodeIterator;
fn prev_iter(&self) -> Self::NodeIterator;
fn attribute_iter(&self) -> Self::NodeIterator;
fn get_attribute(&self, a: &QName) -> Rc<Value>;
fn get_attribute_node(&self, a: &QName) -> Option<Self>;
fn new_element(&self, qn: QName) -> Result<Self, Error>;
fn new_text(&self, v: Rc<Value>) -> Result<Self, Error>;
fn new_attribute(&self, qn: QName, v: Rc<Value>) -> Result<Self, Error>;
fn new_comment(&self, v: Rc<Value>) -> Result<Self, Error>;
fn new_processing_instruction(
&self,
qn: Rc<Value>,
v: Rc<Value>,
) -> Result<Self, Error>;
fn new_namespace(
&self,
ns: NamespaceUri,
prefix: Option<NamespacePrefix>,
in_scope: bool,
) -> Result<Self, Error>;
fn push(&mut self, n: Self) -> Result<(), Error>;
fn pop(&mut self) -> Result<(), Error>;
fn insert_before(&mut self, n: Self) -> Result<(), Error>;
fn add_attribute(&self, att: Self) -> Result<(), Error>;
fn shallow_copy(&self) -> Result<Self, Error>;
fn deep_copy(&self) -> Result<Self, Error>;
fn get_canonical(&self) -> Result<Self, Error>;
fn xmldecl(&self) -> XMLDecl;
fn set_xmldecl(&mut self, d: XMLDecl) -> Result<(), Error>;
fn add_namespace(&self, ns: Self) -> Result<(), Error>;
fn namespace_iter(&self) -> Self::NodeIterator;
fn get_dtd(&self) -> Option<DTD>;
fn set_dtd(&self, dtd: DTD) -> Result<(), Error>;
fn validate(&self, schema: Schema) -> Result<(), ValidationError>;
fn unattached(&self) -> Vec<Self>;
// Provided methods
fn to_json(&self) -> String { ... }
fn is_element(&self) -> bool { ... }
fn first_child(&self) -> Option<Self>
where Self: Sized { ... }
fn parent(&self) -> Option<Self>
where Self: Sized { ... }
fn eq(&self, other: &Self) -> bool { ... }
}Expand description
Nodes make up a document tree. Nodes must be fully navigable. The tree must be mutable but also stable (i.e. removing a node from the tree does not invalidate the remaining nodes).
Some nodes have names, such as elements. Some nodes have values, such as text or comments. Some have both a name and a value, such as attributes and processing instructions.
Element nodes have children and attributes.
Element nodes may have Namespace nodes attached. These are the declaration of XML Namespaces. An XML Namespace declaration consists of an optional prefix and a namespace URI. The namespace-iter() method iterates over all in-scope namespaces, which will include namespaces that are declared on ancestor elements.
Nodes must implement the PartialEq trait. This allows two (sub-)trees to be compared. The comparison is against the XML Infoset of each tree; i.e. do the trees contain the same information, but not necessarily the same string representation. For example, the order of attributes does not matter.
Required Associated Types§
type NodeIterator: Iterator<Item = Self>
Required Methods§
Sourcefn new_document() -> Self
fn new_document() -> Self
Create a Document-type node. All other types of nodes are created using type-specific methods (new_element, new_text, etc).
Sourcefn name(&self) -> Option<QName>
fn name(&self) -> Option<QName>
Get the name of the node, if it has one. A namespace-type returns the prefix as a QName where the prefix is the local-part. An unprefixed namespace node returns None.
Sourcefn value(&self) -> Rc<Value>
fn value(&self) -> Rc<Value>
Get the value of the node. If the node doesn’t have a value, then returns a Value that is an empty string. If the node is a namespace-type node, gives the namespace URI.
Sourcefn to_qname(&self, name: impl AsRef<str>) -> Result<QName, Error>
fn to_qname(&self, name: impl AsRef<str>) -> Result<QName, Error>
Resolve a name using the in-scope namespace declarations in the document, resulting in a Qualified Name. This will fail if the name is not a QName, or has a prefix that is unknown.
Sourcefn to_prefixed_name(&self) -> String
fn to_prefixed_name(&self) -> String
Convert the node’s qualified name to a prefixed name using the in-scope namespace declarations in the document.
Sourcefn to_namespace_prefix(
&self,
nsuri: &NamespaceUri,
) -> Result<Option<NamespacePrefix>, Error>
fn to_namespace_prefix( &self, nsuri: &NamespaceUri, ) -> Result<Option<NamespacePrefix>, Error>
Find the prefix for the given namespace URI using the node’s in-scope namespaces. If the namespace is the default, then None is returned. If the namespace URI is not found in the in-scope namespaces returns an error.
Sourcefn to_namespace_uri(
&self,
prefix: &Option<NamespacePrefix>,
) -> Result<NamespaceUri, Error>
fn to_namespace_uri( &self, prefix: &Option<NamespacePrefix>, ) -> Result<NamespaceUri, Error>
Find the namespace URI for the given namespace prefix using the node’s in-scope namespaces. If the namespace prefix is not found in the in-scope namespaces returns an error.
Sourcefn as_namespace_prefix(&self) -> Result<Option<&NamespacePrefix>, Error>
fn as_namespace_prefix(&self) -> Result<Option<&NamespacePrefix>, Error>
For a namespace node give the prefix. If the namespace is the default namespace, then None is given. If the node is not a namespace-type node then returns an error.
Sourcefn as_namespace_uri(&self) -> Result<&NamespaceUri, Error>
fn as_namespace_uri(&self) -> Result<&NamespaceUri, Error>
For a namespace node give the namespace URI. If the node is not a namespace-type node then returns an error.
Sourcefn is_in_scope(&self) -> bool
fn is_in_scope(&self) -> bool
Is this namespace in scope, or is it a descoping declaration? See Namespaces in XML v1.1 s6.1. This only applies to Namespace-type nodes. All other node types return false.
Sourcefn to_xml_with_options(&self, od: &OutputDefinition) -> String
fn to_xml_with_options(&self, od: &OutputDefinition) -> String
Serialise the node as XML, with options such as indentation.
fn is_attached(&self) -> bool
Sourcefn document_order(&self) -> Vec<usize>
fn document_order(&self) -> Vec<usize>
Get the document order of the node. The value returned is relative to the document containing the node. Depending on the implementation, this value may be volatile; adding or removing nodes to/from the document may invalidate the ordering.
Sourcefn cmp_document_order(&self, other: &Self) -> Ordering
fn cmp_document_order(&self, other: &Self) -> Ordering
Compare the document order of this node with another node in the same document.
Sourcefn is_unattached(&self) -> bool
fn is_unattached(&self) -> bool
Check if a node is unattached
Sourcefn child_iter(&self) -> Self::NodeIterator
fn child_iter(&self) -> Self::NodeIterator
An iterator over the children of the node
Sourcefn ancestor_iter(&self) -> Self::NodeIterator
fn ancestor_iter(&self) -> Self::NodeIterator
An iterator over the ancestors of the node
Sourcefn owner_document(&self) -> Self
fn owner_document(&self) -> Self
Get the document node
Sourcefn descend_iter(&self) -> Self::NodeIterator
fn descend_iter(&self) -> Self::NodeIterator
An iterator over the descendants of the node
Sourcefn next_iter(&self) -> Self::NodeIterator
fn next_iter(&self) -> Self::NodeIterator
An iterator over the following siblings of the node
Sourcefn prev_iter(&self) -> Self::NodeIterator
fn prev_iter(&self) -> Self::NodeIterator
An iterator over the preceding siblings of the node
Sourcefn attribute_iter(&self) -> Self::NodeIterator
fn attribute_iter(&self) -> Self::NodeIterator
An iterator over the attributes of an element
Sourcefn get_attribute(&self, a: &QName) -> Rc<Value>
fn get_attribute(&self, a: &QName) -> Rc<Value>
Get an attribute of the node. Returns a copy of the attribute’s value. If the node does not have an attribute of the given name, a value containing an empty string is returned.
Sourcefn get_attribute_node(&self, a: &QName) -> Option<Self>
fn get_attribute_node(&self, a: &QName) -> Option<Self>
Get an attribute of the node. If the node is not an element returns None. Otherwise returns the attribute node. If the node does not have an attribute of the given name, returns None.
Sourcefn new_element(&self, qn: QName) -> Result<Self, Error>
fn new_element(&self, qn: QName) -> Result<Self, Error>
Create a new element-type node in the same document tree. The new node is not attached to the tree.
Sourcefn new_text(&self, v: Rc<Value>) -> Result<Self, Error>
fn new_text(&self, v: Rc<Value>) -> Result<Self, Error>
Create a new text-type node in the same document tree. The new node is not attached to the tree.
Sourcefn new_attribute(&self, qn: QName, v: Rc<Value>) -> Result<Self, Error>
fn new_attribute(&self, qn: QName, v: Rc<Value>) -> Result<Self, Error>
Create a new attribute-type node in the same document tree. The new node is not attached to the tree.
Sourcefn new_comment(&self, v: Rc<Value>) -> Result<Self, Error>
fn new_comment(&self, v: Rc<Value>) -> Result<Self, Error>
Create a new comment-type node in the same document tree. The new node is not attached to the tree.
Sourcefn new_processing_instruction(
&self,
qn: Rc<Value>,
v: Rc<Value>,
) -> Result<Self, Error>
fn new_processing_instruction( &self, qn: Rc<Value>, v: Rc<Value>, ) -> Result<Self, Error>
Create a new processing-instruction-type node in the same document tree. The new node is not attached to the tree.
Sourcefn new_namespace(
&self,
ns: NamespaceUri,
prefix: Option<NamespacePrefix>,
in_scope: bool,
) -> Result<Self, Error>
fn new_namespace( &self, ns: NamespaceUri, prefix: Option<NamespacePrefix>, in_scope: bool, ) -> Result<Self, Error>
Create a namespace node for an XML Namespace declaration. A namespace may be descoped (see Namespace in XML v1.1). In this case, the prefix and namespace URI are given for the namespace being descoped, but with the in_scope argument ‘false’.
Sourcefn insert_before(&mut self, n: Self) -> Result<(), Error>
fn insert_before(&mut self, n: Self) -> Result<(), Error>
Insert a node in the child list before the given node. The node will be detached from it’s current position prior to insertion.
Sourcefn add_attribute(&self, att: Self) -> Result<(), Error>
fn add_attribute(&self, att: Self) -> Result<(), Error>
Set an attribute. self must be an element-type node. att must be an attribute-type node. Returns an error if an attribute with the same name is already attached to this element.
Sourcefn shallow_copy(&self) -> Result<Self, Error>
fn shallow_copy(&self) -> Result<Self, Error>
Shallow copy the node, i.e. copy only the node, but not it’s attributes or content.
Sourcefn deep_copy(&self) -> Result<Self, Error>
fn deep_copy(&self) -> Result<Self, Error>
Deep copy the node, i.e. the node itself and it’s attributes and descendants. The resulting top-level node is unattached.
Sourcefn get_canonical(&self) -> Result<Self, Error>
fn get_canonical(&self) -> Result<Self, Error>
Canonical XML representation of the node.
Sourcefn set_xmldecl(&mut self, d: XMLDecl) -> Result<(), Error>
fn set_xmldecl(&mut self, d: XMLDecl) -> Result<(), Error>
Set the XML Declaration for the document.
Sourcefn add_namespace(&self, ns: Self) -> Result<(), Error>
fn add_namespace(&self, ns: Self) -> Result<(), Error>
Add a namespace declaration to this element-type node. NOTE: Does NOT assign a namespace to the element. The element’s name defines its namespace.
Sourcefn namespace_iter(&self) -> Self::NodeIterator
fn namespace_iter(&self) -> Self::NodeIterator
An iterator over the namespace nodes of an element. Note: These nodes are calculated at the time the iterator is created. It is not guaranteed that the namespace nodes returned will specify the current element node as their parent.
Sourcefn get_dtd(&self) -> Option<DTD>
fn get_dtd(&self) -> Option<DTD>
Retrieve the internal representation of the DTD, for use in validation functions.
Sourcefn set_dtd(&self, dtd: DTD) -> Result<(), Error>
fn set_dtd(&self, dtd: DTD) -> Result<(), Error>
Store an internal representation of the DTD. Does not keep a copy of the original text
fn validate(&self, schema: Schema) -> Result<(), ValidationError>
Sourcefn unattached(&self) -> Vec<Self>
fn unattached(&self) -> Vec<Self>
Return a list of nodes that are associated with this document, but are not attached.
Provided Methods§
Sourcefn is_element(&self) -> bool
fn is_element(&self) -> bool
Check if a node is an element-type
Sourcefn first_child(&self) -> Option<Self>where
Self: Sized,
fn first_child(&self) -> Option<Self>where
Self: Sized,
Get the first child of the node, if there is one
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".