std1.0.0-beta-7 SafeC docs

Module serial::xml

#include <std/serial/xml.h> source

XML serialization (built on std/serial/value.h)

Same Value tree as json.h (see its top comment for how to make a struct serializable via to_value()); the mapping to XML, since XML elements are always named and JSON's array/object shapes aren't:

- VAL_OBJECT under tag T   -> <T><key1>...</key1><key2>...</key2></T>
  (each object key becomes a child element named after the key)
- VAL_ARRAY under tag T    -> <T><item>...</item><item>...</item></T>
  (array elements have no name of their own, so each becomes <item>)
- VAL_STRING/INT/FLOAT/BOOL -> <T>text content</T>
- VAL_NULL                 -> <T/>

Structs

XmlThe XML backend as a Format (see value.h): v.encode(Xml::new("doc")), Value::decode(Xml::new("doc"), text, &ok). write emits one element named root; parse returns the root element's content (as xml_parse).

Functions

xml_writeAppends v's XML representation (as a single element named 'tag') to 'out'.
value_to_xmlConvenience wrapper: a fresh String holding just that one element.
xml_parseParses this module's own output shape back into a Value tree (root tag itself is not returned — only its content, mirroring json_parse). Sets *ok to 0 (and returns VAL_NULL) on malformed input. This is a parser for xml_write's specific grammar, not general XML (no attributes, CDATA, or entities beyond the 5 xml_append_escaped_ emits) — see xml.sc's parser section for the two structural ambiguities inherent to this grammar (empty string vs. empty object; numeric-looking text vs. string).