cleanup, docs
This commit is contained in:
@@ -23,49 +23,18 @@ Try the live example in the [XML demo](../demo/xml.uce).
|
||||
|
||||
The native element shape is:
|
||||
|
||||
```text
|
||||
node["name"] = "book"
|
||||
node["attrs"]["id"] = "b1"
|
||||
node["text"] = "optional text"
|
||||
node["children"] = list of child element nodes
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```uce
|
||||
DValue book;
|
||||
book["name"] = "book";
|
||||
book["attrs"]["id"] = "b1";
|
||||
|
||||
DValue title;
|
||||
title["name"] = "title";
|
||||
title["text"] = "UCE & XML";
|
||||
book["children"].push(title);
|
||||
|
||||
String xml = xml_encode(book);
|
||||
```
|
||||
|
||||
The result is:
|
||||
|
||||
```xml
|
||||
<book id="b1"><title>UCE & XML</title></book>
|
||||
```
|
||||
|
||||
For simple map/list/scalar trees, `xml_encode()` creates ordinary child elements:
|
||||
|
||||
```uce
|
||||
DValue payload;
|
||||
payload["title"] = "Hello";
|
||||
payload["count"] = "3";
|
||||
|
||||
String xml = xml_encode(payload, "payload");
|
||||
```
|
||||
|
||||
Result:
|
||||
|
||||
```xml
|
||||
<payload><count>3</count><title>Hello</title></payload>
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
||||
@@ -74,3 +43,8 @@ Notes:
|
||||
- List values use repeated `<item>` children.
|
||||
- Empty elements serialize as self-closing tags.
|
||||
- Map child order follows `DValue` map iteration order.
|
||||
|
||||
:example
|
||||
DValue value;
|
||||
value["name"] = "Ada";
|
||||
print(xml_encode(value) != "" ? "xml\n" : "empty\n");
|
||||
|
||||
Reference in New Issue
Block a user