pub struct XmlManager;Expand description
Structure responsible for managing XML file reading and parsing.
Implementations§
Source§impl XmlManager
impl XmlManager
Sourcepub fn read_xml(path: &str) -> Rawdata
pub fn read_xml(path: &str) -> Rawdata
Reads an XML file and parses into a Rawdata struct.
This function opens the specified XML file, parses it using roxmltree,
and fills a Rawdata struct with information about the instance name,
teams, slots, distances, capacity constraints, and separation constraints.
The XML elements are mapped as follows:
<InstanceName>→Rawdata.instance_name<team>→Rawdata.teams<slot>→Rawdata.slots<distance>→Rawdata.distances- Elements starting with
"CA"→Rawdata.capacity_constraints - Elements starting with
"SE"→Rawdata.separation_constraints
§Arguments
path- A string slice representing the path to the XML file.
§Returns
A Rawdata struct containing all parsed information from the XML.
§Panics
This function will panic if the XML file cannot be opened or parsed.
§Example
let raw_data = read_xml("instances/example.xml");
println!("Instance name: {}", raw_data.instance_name);
println!("Number of teams: {}", raw_data.teams.len());Sourcefn parse_team(node: &Node<'_, '_>) -> Team
fn parse_team(node: &Node<'_, '_>) -> Team
Parses a <Team> XML node and converts it into a Team struct.
This function reads the attributes of the given XML node and fills the corresponding
fields in Team. If a numeric attribute is missing or cannot be parsed, it defaults to 0.
§Arguments
node- A reference to aroxmltree::Noderepresenting the<Team>element.
§Returns
A Team struct populated with the parsed values.
§Example
let doc = roxmltree::Document::parse(r#"<Team id="5" league="1" name="Eagles" teamGroups="2"/>"#).unwrap();
let node = doc.root_element();
let team = parse_team(&node);
assert_eq!(team.id, 5);
assert_eq!(team.league, 1);
assert_eq!(team.name, "Eagles".to_string());
assert_eq!(team.team_groups, 2);Sourcefn parse_slot(node: &Node<'_, '_>) -> Slot
fn parse_slot(node: &Node<'_, '_>) -> Slot
Parses a <Slot> XML node and converts it into a Slot struct.
This function reads the attributes of the given XML node and fills the corresponding
fields in Slot. If an attribute is missing or cannot be parsed as a number,
it defaults to 0.
§Arguments
node- A reference to aroxmltree::Noderepresenting the<Slot>element.
§Returns
A Slot struct populated with the parsed values.
§Example
let doc = roxmltree::Document::parse(r#"<Slot id="3" name="ATL"/>"#).unwrap();
assert_eq!(doc.id, 3);
assert_eq!(doc.name, "ATL".to_string());Sourcefn parse_distance(node: &Node<'_, '_>) -> Distance
fn parse_distance(node: &Node<'_, '_>) -> Distance
Parses a <Distance> XML node and converts it into a Distance struct.
This function reads the attributes of the given XML node and fills the corresponding
fields in Distance. If an attribute is missing or cannot be parsed as a number,
it defaults to 0.
§Arguments
node- A reference to aroxmltree::Noderepresenting the<Distance>element.
§Returns
A Distance struct populated with the parsed values.
§Example
let doc = roxmltree::Document::parse(r#"<Distance dist="15" team1="2" team2="5"/>"#).unwrap();
let node = doc.root_element();
let distance = parse_distance(&node);
assert_eq!(distance.dist, 15);
assert_eq!(distance.team1, 2);
assert_eq!(distance.team2, 5);Sourcefn parse_capacity(node: &Node<'_, '_>) -> CapacityConstraints
fn parse_capacity(node: &Node<'_, '_>) -> CapacityConstraints
Parses a <CapacityConstraints> XML node and converts it into a CapacityConstraints struct.
This function reads the attributes of the given XML node and fills the corresponding
fields in CapacityConstraints. If an attribute is missing or cannot be parsed,
numeric fields default to 0.
§Arguments
node- A reference to aroxmltree::Noderepresenting the<CapacityConstraints>element.
§Returns
A CapacityConstraints struct populated with the parsed values.
§Example
let doc = roxmltree::Document::parse(r#"<Capacity intp="2" max="5" min="1" mode1="H" mode2="A" penalty="10" teamGroups1="3" teamGroups2="2" type="hard"/>"#).unwrap();
let node = doc.root_element();
let capacity = parse_capacity(&node);
assert_eq!(capacity.c_intp, 2);
assert_eq!(capacity.c_type, "hard".to_string());Sourcefn parse_separation(node: &Node<'_, '_>) -> SeparationConstraints
fn parse_separation(node: &Node<'_, '_>) -> SeparationConstraints
Parses a <SeparationConstraint> XML node and converts it into a SeparationConstraints struct.
This function reads the attributes of the given XML node and fills the corresponding
fields in SeparationConstraints. If an attribute is missing or cannot be parsed
as a number, it defaults to 0.
§Arguments
node- A reference to aroxmltree::Noderepresenting the<SeparationConstraint>element.
§Returns
A SeparationConstraints struct populated with the parsed values.
§Example
let doc = roxmltree::Document::parse(r#"<Separation max="3" min="1" penalty="5" teamGroups="2" type="soft"/>"#).unwrap();
let node = doc.root_element();
let separation = parse_separation(&node);
assert_eq!(separation.c_max, 3);
assert_eq!(separation.c_type, "soft".to_string());