Rust
Rust
Demonstrate the XML UpdateAttrAt Method
See more XML Examples
Demonstrates the XML UpdateAttrAt method to update attribute name/value pairs in XML.Note: This example requires Chilkat v9.5.0.64 or later.
Chilkat Rust Downloads
// Note: This example requires Chilkat v9.5.0.64 or later.
let xml = chilkat::Xml::new();
xml.set_tag("animals");
let auto_create = true;
// When the autoCreate argument equals true, the UpdateAttrAt
// method auto-creates the children as needed:
let _ = xml.update_attr_at("penguin", auto_create, "feature", "flightless bird");
let _ = xml.update_attr_at("mammal|rodent|squirrel", auto_create, "feature", "bushy tail");
let _ = xml.update_attr_at("mammal|rodent|rat", auto_create, "feature", "long hairless tail");
// Show the XML
println!("{}", xml.get_xml().unwrap_or_default());
// <?xml version="1.0" encoding="utf-8" ?>
// <animals>
// <penguin feature="flightless bird" />
// <mammal>
// <rodent>
// <squirrel feature="bushy tail" />
// <rat feature="long hairless tail" />
// </rodent>
// </mammal>
// </animals>
//
// Now update each node's "feature" attribute..
let _ = xml.update_attr_at("penguin", auto_create, "feature", "black and white");
let _ = xml.update_attr_at("mammal|rodent|squirrel", auto_create, "feature", "grey, red, or black");
let _ = xml.update_attr_at("mammal|rodent|rat", auto_create, "feature", "brown, grey, white, or black");
println!("{}", xml.get_xml().unwrap_or_default());
// <?xml version="1.0" encoding="utf-8" ?>
// <animals>
// <penguin feature="black and white" />
// <mammal>
// <rodent>
// <squirrel feature="grey, red, or black" />
// <rat feature="brown, grey, white, or black" />
// </rodent>
// </mammal>
// </animals>
//