pub struct Node {
pub tag: String,
pub attributes: HashMap<String, String>,
pub content: String,
/* private fields */
}
Fields§
§tag: String
§attributes: HashMap<String, String>
§content: String
Implementations§
Source§impl Node
impl Node
Sourcepub fn get_nodes(&self, tag: &str) -> Option<&Vec<Node>>
pub fn get_nodes(&self, tag: &str) -> Option<&Vec<Node>>
Returns a list of all nodes with the specified tag If no nodes with the specified tag exists, None is returned
Sourcepub fn try_get_nodes(&self, tag: &str) -> Result<&Vec<Node>, Error>
pub fn try_get_nodes(&self, tag: &str) -> Result<&Vec<Node>, Error>
Returns a list of all nodes with the specified tag If no nodes with the specified tag exists, an Err of TagNotFound is returned containing the parent name and requested node name Otherwise, works exactly like get_nodes but can be chained with ? (try operator)
Sourcepub fn add_attribute(&mut self, key: &str, val: &str) -> Option<String>
pub fn add_attribute(&mut self, key: &str, val: &str) -> Option<String>
Adds or updates an attribute If an attribute with that key already exists it is returned
pub fn get_attribute(&self, key: &str) -> Option<&String>
Sourcepub fn try_get_attribute(&self, key: &str) -> Result<&String, Error>
pub fn try_get_attribute(&self, key: &str) -> Result<&String, Error>
Gets an attribute by name or returns an Err of AttributeNotFound containing the parent tag and the requested key Otherwise, works exactly like get_nodes but can be chained with ? (try operator)
Sourcepub fn add_new_node(&mut self, tag: &str, content: String)
pub fn add_new_node(&mut self, tag: &str, content: String)
Inserts a new node into the xml structure Does the same thing as node.add_node(simple_xml::new(tag, content));
Sourcepub fn save_to_file<P: AsRef<Path>>(&self, path: P) -> Result<()>
pub fn save_to_file<P: AsRef<Path>>(&self, path: P) -> Result<()>
This writes an xml structure to a file specified by path Uses the non-pretty to_string formatting
Sourcepub fn save_to_file_pretty<P: AsRef<Path>>(&self, path: P) -> Result<()>
pub fn save_to_file_pretty<P: AsRef<Path>>(&self, path: P) -> Result<()>
This writes an xml structure to a file specified by path Uses the pretty to_string_pretty formatting