macro_rules! xml {
($($xml:tt)+) => { ... };
}
Expand description
Construct an XmlValue
from an XML-like literal.
let value/*: xmlity:::value::XmlElement*/ = xml!(
<"root">[
<"child" "attribute"="value">["Text"]</"child">
<![CDATA["CData content"]]>
<?"pi-target" "instruction"?>
<!-- "Comment" -->
"Text node"
<"child2":"http://example.com" "attr1"="value1" "attr2"="value2">[]</"child2">
]</"root">
);
The macro supports the following XML constructs:
- Elements with attributes
- Text nodes
- CDATA sections
- Processing instructions
- Comments
- Sequences of children
The macro will automatically choose between an XmlSeq
and a value-type depending on if the top-level element is a sequence or not.
For example, the value above is an XmlElement
with a sequence of children, while the example below returns an XmlSeq
:
let value/*: xmlity::value::XmlSeq<_>*/ = xml!(
<"child" "attribute"="value">["Text"]</"child">
<"child" "attribute"="value">["Text"]</"child">
);