Skip to main content

XmlNode

Struct XmlNode 

Source
pub struct XmlNode {
    pub name: String,
    pub attrs: Vec<(String, String)>,
    pub children: Vec<XmlNode>,
    pub text: Option<String>,
}
Expand description

XML 节点(解析中间表示)。

quick-xml 解析结果归一化为统一的节点树,XmlElement::from_xml 从节点 恢复类型。

Fields§

§name: String

元素名(不含命名空间前缀,如 “TextObject”)。

§attrs: Vec<(String, String)>

属性列表(保序)。

§children: Vec<XmlNode>

子元素。

§text: Option<String>

文本内容(若为文本节点)。

Implementations§

Source§

impl XmlNode

Source

pub fn element(name: impl Into<String>) -> Self

创建元素节点。

Source

pub fn text_node(text: impl Into<String>) -> Self

创建文本节点。

Source

pub fn attr(self, key: impl Into<String>, value: impl Into<String>) -> Self

添加属性。

Source

pub fn push_child(&mut self, child: XmlNode)

添加子元素。

Source

pub fn get_attr(&self, key: &str) -> Option<&str>

读取属性值。

Source

pub fn child(&self, name: &str) -> Option<&XmlNode>

首个匹配名字的子元素。

Source

pub fn children_named<'a>( &'a self, name: &'a str, ) -> impl Iterator<Item = &'a XmlNode>

所有匹配名字的子元素。

Source

pub fn to_xml_string(&self) -> String

将节点序列化为 XML 片段(不含 XML 声明)。

对应 Java: OFDElement.toString()

Trait Implementations§

Source§

impl Clone for XmlNode

Source§

fn clone(&self) -> XmlNode

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
Source§

impl Debug for XmlNode

Source§

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

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

impl PartialEq for XmlNode

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for XmlNode

Auto Trait Implementations§

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.