Skip to main content

XmlText

Struct XmlText 

Source
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> &amp; <![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>

Source

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 &amp; not decoded. Use unescaped to decode them.

Source

pub fn is_cdata(&self) -> bool

Whether this node is a CDATA section.

Source

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 &lt; 2</math>");
let text = reader.root_element()?.text_node().unwrap();
assert_eq!(text.text(), "1 &lt; 2");
assert_eq!(text.unescaped(), "1 < 2");
Source

pub fn range(&self) -> Range<usize> ⓘ

Byte range of this node in the source text (including CDATA markers).

Source

pub fn next_sibling(&self) -> Option<BodyNode<'xml>>

Next sibling node within the parent element, or None.

Trait Implementations§

Source§

impl<'xml> Clone for XmlText<'xml>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more

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> 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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.