do_xml

Macro do_xml 

Source
macro_rules! do_xml {
    ($content:expr, $($key:ident = $val:expr),*) => { ... };
}
Expand description

§do_xml!($content, $key, and $val)

Macro Rules

The do_xml macro takes XML string content along with key-value pairs and replaces placeholders in the XML (formatted as {{key}}) with the corresponding values. It returns the processed XML string with the substitutions applied.

§Parameters

  • $content: The XML string content containing placeholders for substitution (e.g., "<p>Hello, {{name}}!</p>").
  • $key: The identifier for each placeholder in the XML (e.g., name).
  • $val: The value that replaces the corresponding placeholder in the XML (e.g., "Alice").

§Examples

// use cans::content::do_xml;
use cans::do_xml;

let xml_content = "<note><to>{{recipient}}</to></note>";
let xml_result = do_xml!(xml_content, recipient = "Ahmed");
assert_eq!(xml_result, "<note><to>Ahmed</to></note>");

End Doc