pub enum Node {
Element(Element),
Text(String),
Comment(String),
CData(String),
PI(String),
DocType(String),
}
Expand description
Represents an XML node.
Variants§
Element(Element)
XML Element
Text(String)
XML Character Data (specification)
Comment(String)
Comments (specification)
CData(String)
CDATA (specification)
PI(String)
Processing Instruction (specification)
DocType(String)
Document Type Declaration (specification)
Implementations§
Source§impl Node
impl Node
Sourcepub fn as_element(&self) -> Option<Element>
pub fn as_element(&self) -> Option<Element>
Useful to use inside filter_map
.
use edit_xml::{Document, Element};
let mut doc = Document::parse_str(r#"<?xml version="1.0" encoding="UTF-8"?>
<config>
Random Text
<max>1</max>
</config>
"#).unwrap();
let elems: Vec<Element> = doc
.root_element()
.unwrap()
.children(&doc)
.iter()
.filter_map(|n| n.as_element())
.collect();
Sourcepub fn text_content(&self, doc: &Document) -> String
pub fn text_content(&self, doc: &Document) -> String
Returns content if node is Text
, CData
, or PI
.
If node is Element
, return Element::text_content()
Implementation of Node.textContent
Sourcepub fn possible_borrowed_text(&self) -> Option<Cow<'_, str>>
pub fn possible_borrowed_text(&self) -> Option<Cow<'_, str>>
Returns content if node is Text
, CData
, or PI
.
If node is Element
Cow will be owned.
Otherwise, Cow will be borrowed.
If None is returned it is a comment or doctype
Sourcepub fn debug<'node, 'doc>(
&'node self,
doc: &'doc Document,
) -> NodeDebug<'node, 'doc>
pub fn debug<'node, 'doc>( &'node self, doc: &'doc Document, ) -> NodeDebug<'node, 'doc>
Debug the node
Sourcepub fn is_text(&self) -> bool
pub fn is_text(&self) -> bool
Returns true if the node is a text node
use edit_xml::Node;
let node = Node::Text("Hello".to_string());
assert!(node.is_text());
Sourcepub fn is_comment(&self) -> bool
pub fn is_comment(&self) -> bool
Returns true if the node is a comment node
use edit_xml::Node;
let node = Node::Comment("Hello".to_string());
assert!(node.is_comment());
Sourcepub fn is_cdata(&self) -> bool
pub fn is_cdata(&self) -> bool
Returns true if the node is a CDATA node
use edit_xml::Node;
let node = Node::CData("Hello".to_string());
assert!(node.is_cdata());
Sourcepub fn is_pi(&self) -> bool
pub fn is_pi(&self) -> bool
Returns true if the node is a Processing Instruction node
use edit_xml::Node;
let node = Node::PI("Hello".to_string());
assert!(node.is_pi());
Sourcepub fn is_doctype(&self) -> bool
pub fn is_doctype(&self) -> bool
Returns true if the node is a Document Type Declaration
use edit_xml::Node;
let node = Node::DocType("Hello".to_string());
assert!(node.is_doctype());
Sourcepub fn is_element(&self) -> bool
pub fn is_element(&self) -> bool
Returns true if the node is an element