Macro inline_xml::xml

source ·
xml!() { /* proc-macro */ }
Expand description

Generate an Xml struct from XML. This macro allows specifying multiple XML root nodes. If you only want a single XML node, please use xml_tag.

Examples

XML configuration generator

This example generates a simple XML config file generator.

use inline_xml::{Xml, xml};
fn config(name: &str, age: u8) -> Xml {
    xml! {
        <name>{name}</name>
        <age>{age}</age>
    }
}

Simple inline-xml website

use inline_xml::{Xml, xml};
fn index() -> Xml {
    xml! {
        <html>
            <head>
                <title>Example Website</title>
                <meta charset="UTF-8" />
            </head>
            <body>
                <h1 align="center">Example Website</h1>
                <p style="color: red;">"This is an example website."</p>
                <p>"Here are some escaped characters: &<>\"'"</p>
            </body>
        </html>
    }
}

Simple inline-xml form

use inline_xml::{Tag, xml_tag};
fn form() -> Tag {
    xml_tag! {
        <form action="/login" method="post">
            <label>Username:</label><br />
            <input type="text" name="username" />
            <label>Password:</label><br />
            <input type="password" name="password" />
            <button type="submit">Login</button>
        </form>
    }
}