pub struct XmlText<'xml> { /* private fields */ }Expand description
A text node in the body of an element.
Covers both plain character data and <![CDATA[…]]> sections; text()
always returns the text content without CDATA markers.
Leading and trailing whitespace is part of the text. Whitespace-only text between markup, typically indentation, does not form a text node.
§Examples
use roxml::prelude::*;
let reader = XmlReader::parse("<p>Hello <b>XML</b> & <![CDATA[<world>]]></p>");
let texts: Vec<String> = reader
.root_element()?
.children()
.filter_map(|node| match node {
BodyNode::Text(t) => Some(t.unescaped().to_string()),
_ => None,
})
.collect();
assert_eq!(texts, ["Hello ", " & ", "<world>"]);Implementations§
Source§impl<'xml> XmlText<'xml>
impl<'xml> XmlText<'xml>
Sourcepub fn text(&self) -> &'xml str
pub fn text(&self) -> &'xml str
Raw text content. For CDATA sections the <![CDATA[ / ]]> markers are
stripped; plain text is returned as written, with entity references
such as & not decoded. Use unescaped to
decode them.
Sourcepub fn unescaped(&self) -> Unescaped<'xml>
pub fn unescaped(&self) -> Unescaped<'xml>
Text content with entity references decoded, see Unescaped.
CDATA sections are not decoded, only their line ends are normalized.
§Examples
use roxml::XmlReader;
let reader = XmlReader::parse("<math>1 < 2</math>");
let text = reader.root_element()?.text_node().unwrap();
assert_eq!(text.text(), "1 < 2");
assert_eq!(text.unescaped(), "1 < 2");Sourcepub fn range(&self) -> Range<usize> ⓘ
pub fn range(&self) -> Range<usize> ⓘ
Byte range of this node in the source text (including CDATA markers).
Sourcepub fn next_sibling(&self) -> Option<BodyNode<'xml>>
pub fn next_sibling(&self) -> Option<BodyNode<'xml>>
Next sibling node within the parent element, or None.
Trait Implementations§
Auto Trait Implementations§
impl<'xml> Forget for XmlText<'xml>
impl<'xml> Freeze for XmlText<'xml>
impl<'xml> RefUnwindSafe for XmlText<'xml>
impl<'xml> Send for XmlText<'xml>
impl<'xml> Sync for XmlText<'xml>
impl<'xml> Unpin for XmlText<'xml>
impl<'xml> UnsafeUnpin for XmlText<'xml>
impl<'xml> UnwindSafe for XmlText<'xml>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more