calog/libs/calogXml.h

30 lines
1.4 KiB
C

// calogXml.h -- calog XML library.
//
// Bridges XML text and calog's value/aggregate model, so any engine can parse and produce
// XML without an engine-specific library:
// xmlParse(text) -> element (the document's root element node)
// xmlStringify(node) -> XML text
//
// An element node is a map:
// { "tag": string, "attr": { name: value, ... }, "children": [ node | text, ... ] }
// where each child is either a nested element map or a plain string (a text node). The "attr"
// key is present only when the element has attributes. Mixed content and all character data
// (including whitespace between elements) are preserved, so parse -> stringify is lossless for
// element structure; comments, processing instructions, and the XML declaration are dropped.
//
// Parsing uses vendored libxml2 (SAX) with networking off and no external-entity loading (no
// XXE). Nesting is bounded by CALOG_MAX_DEPTH both ways. Marshalling is binary-safe (UTF-8). The
// natives are INLINE (pure computation, no shared state): libxml2 self-initializes thread-safely
// when a parser context is created and frees its per-thread state on thread exit, so there is
// nothing to shut down.
#ifndef CALOG_XML_H
#define CALOG_XML_H
#include "calog.h"
// Register the XML natives (xmlParse, xmlStringify) on a runtime. Stateless: safe to call on any
// number of runtimes, and there is no matching shutdown.
int32_t calogXmlRegister(CalogT *calog);
#endif