Struct simple_xml_serialize::XMLElement [−][src]
pub struct XMLElement { pub name: String, pub contents: Option<Vec<XMLElement>>, pub text: Option<String>, pub attrs: Option<Vec<XMLAttr>>, pub raw: Option<String>, }
The basic type this crate provides. Functions are provided for setting/adding to the fields in this struct. Any manipulation past that is left to the user by accessing the fields directly.
Fields
name: String
The tag for this element node. IE <myelement/>
contents: Option<Vec<XMLElement>>
Nested XMLElements. IE <myelement><nested/></myelement>
text: Option<String>
Plain character data inside of the node. IE <myelement>hello world</myelement>
attrs: Option<Vec<XMLAttr>>
The key/value pairs inside of an element tag. IE <myelement attr1="hello" attr2="world"/>
raw: Option<String>
Allows for writing raw string contents that won’t have special characters replaced. Useful for including already properly formed xml without it having to be an XMLElement. Placed after ‘contents’ and before ‘text’
Implementations
impl XMLElement
[src]
pub fn new(name: &str) -> Self
[src]
Constructs a new XMLElement with the given name and None
for the rest of the fields
Arguments
name
- A string slice that holds the name of the XML element displayed at the element root
Example
use simple_xml_serialize::XMLElement; let ele = XMLElement::new("name"); assert_eq!(ele.to_string(), String::from("<name/>"));
pub fn name(self, name: &str) -> Self
[src]
Builder pattern function for changing the name of an XMLElement
Arguments
name
- A string slice that holds the name of the XML element displayed at the element root
Example
let ele = XMLElement::new("name").name("changed"); assert_eq!(ele.to_string(), String::from("<changed/>"));
pub fn set_name(&mut self, name: &str)
[src]
Changes the name of an XMLElement
Arguments
name
- A string slice that holds the name of the XML element displayed at the element root
Example
let mut ele = XMLElement::new("name"); ele.set_name("changed"); assert_eq!(ele.to_string(), String::from("<changed/>"));
pub fn attr(self, attr: &str, attr_val: impl ToString) -> Self
[src]
Builder pattern function for adding an attribute to the XMLElement
Arguments
attr
- A string slice that holds the name of the attributeattr_val
- Any type that implements ToString; the value of the attribute
Example
let ele = XMLElement::new("name").attr("my_attr", 1); assert_eq!(ele.to_string(), String::from(r#"<name my_attr="1"/>"#));
pub fn add_attr(&mut self, attr: &str, attr_val: impl ToString)
[src]
Adds an attribute to the XMLElement
Arguments
attr
- A string slice that holds the name of the attributeattr_val
- Any type that implements ToString; the value of the attribute
Example
let mut ele = XMLElement::new("name"); ele.add_attr("my_attr", 1); assert_eq!(ele.to_string(), String::from(r#"<name my_attr="1"/>"#));
pub fn element(self, new_ele: impl Into<XMLElement>) -> Self
[src]
Builder pattern function for adding an element to the contents of this XMLElement
Arguments
new_ele
- Any type that implementsInto<XMLElement>
Example
struct MyPoint {} impl From<MyPoint> for XMLElement { fn from(p: MyPoint) -> Self { XMLElement::new("point") } } let ele = XMLElement::new("name").element(MyPoint{}); assert_eq!(ele.to_string(), String::from("<name><point/></name>"));
pub fn add_element(&mut self, new_ele: impl Into<XMLElement>)
[src]
Adds an element to the contents of this XMLElement
Arguments
new_ele
- Any type that implementsInto<XMLElement>
Example
let mut ele = XMLElement::new("name"); ele.add_element(MyPoint{}); assert_eq!(ele.to_string(), String::from("<name><point/></name>"));
pub fn elements<T>(self, new_eles: T) -> Self where
T: IntoIterator,
T::Item: Into<XMLElement>,
[src]
T: IntoIterator,
T::Item: Into<XMLElement>,
Builder pattern for adding a collection of elements to the contents of this XMLElement
Arguments
new_eles
- Any collection ofInto<XMLElement>
as long as that collection implementsIntoIterator
Example
let points: Vec<MyPoint> = vec![MyPoint{}, MyPoint{}]; let mut ele = XMLElement::new("name").elements(points); assert_eq!(ele.to_string(), String::from("<name><point/><point/></name>"));
pub fn add_elements<T>(&mut self, new_eles: T) where
T: IntoIterator,
T::Item: Into<XMLElement>,
[src]
T: IntoIterator,
T::Item: Into<XMLElement>,
Adds a collection of elements to the contents of this XMLElement
Arguments
new_eles
- Any collection ofInto<XMLElement>
as long as that collection implementsIntoIterator
Example
let points: Vec<MyPoint> = vec![MyPoint{}, MyPoint{}]; let mut ele = XMLElement::new("name"); ele.add_elements(points); assert_eq!(ele.to_string(), String::from("<name><point/><point/></name>"));
pub fn add_elements_with_name<T>(&mut self, new_name: &str, new_eles: T) where
T: IntoIterator,
T::Item: Into<XMLElement>,
[src]
T: IntoIterator,
T::Item: Into<XMLElement>,
Adds a collection of elements to the contents of this XMLElement and changes the element name of each
Arguments
new_name
- A string slice containing the name to use when adding the elementsnew_eles
- Any collection ofInto<XMLElement>
as long as that collection implementsIntoIterator
Example
let mut ele = XMLElement::new("name"); let points: Vec<MyPoint> = vec![MyPoint{}, MyPoint{}]; ele.add_elements_with_name("p", points); assert_eq!(ele.to_string(), String::from("<name><p/><p/></name>"));
pub fn raw(self, raw: impl ToString) -> Self
[src]
Builder pattern function for adding raw content to the XMLElement. In the ToString implementation for XMLElement, raw content is placed after normal contents and before text.
Arguments
raw
- Any type that implements ToString; content in the element
Example
let ele = XMLElement::new("name").raw("<raw_content>Some content</raw_content>"); assert_eq!(ele.to_string(), String::from("<name><raw_content>Some content</raw_content></name>"));
pub fn set_raw(&mut self, raw: impl ToString)
[src]
Adds raw text to the contents of the XMLElement. In the ToString implementation for XMLElement, raw content is placed after normal contents and before text.
Arguments
text
- Any type that implements ToString; text in the element
Example
let mut ele = XMLElement::new("name"); ele.set_raw("<raw_content>Some content</raw_content>"); assert_eq!(ele.to_string(), String::from("<name><raw_content>Some content</raw_content></name>"));
pub fn text(self, text: impl ToString) -> Self
[src]
Builder pattern function for adding raw text to the contents of the XMLElement. In the ToString implementation for XMLElement, raw text is always placed after all other contents.
Arguments
text
- Any type that implements ToString; text in the element
Example
let ele = XMLElement::new("name").text("Some content"); assert_eq!(ele.to_string(), String::from("<name>Some content</name>"));
pub fn set_text(&mut self, text: impl ToString)
[src]
Adds raw text to the contents of the XMLElement. In the ToString implementation for XMLElement, raw text is always placed after all other contents.
Arguments
text
- Any type that implements ToString; text in the element
Example
let mut ele = XMLElement::new("name"); ele.set_text("Some content"); assert_eq!(ele.to_string(), String::from("<name>Some content</name>"));
pub fn to_string_pretty(&self, newline: &str, indent: &str) -> String
[src]
Returns the string representation of the XMLElement, but with newlines and the given indentation
Arguments
indent
- A string slice containing the characters to use to indent the document
Example
let mut ele = XMLElement::new("name"); ele.set_text("Some content"); ele.add_element(MyPoint{}); let expected = String::from(r#"<name> <point/> Some content </name>"#); assert_eq!(ele.to_string_pretty("\n", " "), expected);
pub fn to_string_pretty_prolog(&self, newline: &str, indent: &str) -> String
[src]
Returns the string representation of the XMLElement, but with newlines and the given indentation and an xml prolog
Arguments
indent
- A string slice containing the characters to use to indent the document
Example
let mut ele = XMLElement::new("name"); ele.set_text("Some content"); ele.add_element(MyPoint{}); let expected = String::from(r#"<?xml version="1.0" encoding="UTF-8"?> <name> <point/> Some content </name>"#); assert_eq!(ele.to_string_pretty_prolog("\n", " "), expected);
Trait Implementations
impl Clone for XMLElement
[src]
fn clone(&self) -> XMLElement
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for XMLElement
[src]
impl Display for XMLElement
[src]
impl From<&'_ XMLElement> for XMLElement
[src]
fn from(e: &XMLElement) -> Self
[src]
impl PartialEq<XMLElement> for XMLElement
[src]
fn eq(&self, other: &XMLElement) -> bool
[src]
fn ne(&self, other: &XMLElement) -> bool
[src]
impl StructuralPartialEq for XMLElement
[src]
Auto Trait Implementations
impl RefUnwindSafe for XMLElement
impl Send for XMLElement
impl Sync for XMLElement
impl Unpin for XMLElement
impl UnwindSafe for XMLElement
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,