Struct xml_schema_generator::Element
source · pub struct Element<T> {
pub name: T,
pub text: Option<T>,
/* private fields */
}
Expand description
represents the structure and characteristics of an XML element
Fields§
§name: T
§text: Option<T>
Implementations§
source§impl<T: PartialEq + Display + Debug> Element<T>
impl<T: PartialEq + Display + Debug> Element<T>
pub fn new(name: T, attributes: Vec<T>) -> Element<T>
sourcepub fn formatted_name(&self) -> String
pub fn formatted_name(&self) -> String
format the name of the element to be properly represented as a Rust struct
sourcepub fn standalone(&self) -> bool
pub fn standalone(&self) -> bool
return true if this tag always appears only 0 or 1 times within it’s parent element return false if this tag appears at least once more than 1 times within it’s parent element
sourcepub fn set_multiple(&mut self)
pub fn set_multiple(&mut self)
call this function if this element appears more than once inside a parent element
sourcepub fn count(&self) -> u32
pub fn count(&self) -> u32
return how often the element is present inside the current parent element, only used during parsing an XML document
sourcepub fn increment(&mut self)
pub fn increment(&mut self)
increase the counter by one, only used during parsing an XML document
sourcepub fn merge_attr(self, attributes: Vec<Necessity<T>>) -> Element<T>
pub fn merge_attr(self, attributes: Vec<Necessity<T>>) -> Element<T>
merge the given list of attributes into the list if the element’s attributes attributes that not appear in both lists are marked as optional
Example
use xml_schema_generator::Element;
use xml_schema_generator::Necessity;
let mut root = Element::new("car", vec!["name", "colour"]);
root = root.merge_attr(vec![Necessity::Mandatory("name"), Necessity::Mandatory("type")]);
sourcepub fn add_unique_child(&mut self, child: Element<T>)
pub fn add_unique_child(&mut self, child: Element<T>)
add a new child element to this element, if it does not exist yet
sourcepub fn set_child_optional(&mut self, name: &T)
pub fn set_child_optional(&mut self, name: &T)
find a child element with the given name, mark it as optional if found
sourcepub fn get_child(&self, name: &T) -> Option<&Necessity<Element<T>>>
pub fn get_child(&self, name: &T) -> Option<&Necessity<Element<T>>>
find a child element by name and return a reference to it if found
sourcepub fn get_child_mut(&mut self, name: &T) -> Option<&mut Necessity<Element<T>>>
pub fn get_child_mut(&mut self, name: &T) -> Option<&mut Necessity<Element<T>>>
find a child element by name and return it as mutable reference if found