45 lines
1.4 KiB
C
45 lines
1.4 KiB
C
// Part of JoeyLib, Copyright (c) 2026 Scott Duensing, under the MIT License.
|
|
// See LICENSE.md for license information.
|
|
// SPDX-License-Identifier: MIT
|
|
//
|
|
// toolXml.h - a small XML reader for the JoeyLib host tools (Tiled's TMX
|
|
// and TSX): a document as a tree of elements, each with its attributes and
|
|
// children in order and the text before its first child (as Python's
|
|
// ElementTree keeps it). Entities and character references are decoded;
|
|
// comments, processing instructions, and a DOCTYPE are skipped; CDATA is
|
|
// text. UTF-8 only; no namespaces, no DTD entities.
|
|
|
|
#ifndef TOOL_XML_H
|
|
#define TOOL_XML_H
|
|
|
|
#include <stddef.h>
|
|
|
|
#define TOOL_XML_ERROR_BYTES 160u
|
|
|
|
typedef struct ToolXmlAttrT {
|
|
char *name;
|
|
char *value;
|
|
} ToolXmlAttrT;
|
|
|
|
typedef struct ToolXmlT {
|
|
char *name;
|
|
ToolXmlAttrT *attrs;
|
|
size_t attrCount;
|
|
struct ToolXmlT **children;
|
|
size_t childCount;
|
|
char *text;
|
|
} ToolXmlT;
|
|
|
|
// The document's root element, or NULL with the reason in err.
|
|
ToolXmlT *toolXmlParse(const char *text, size_t len, char err[TOOL_XML_ERROR_BYTES]);
|
|
|
|
// Free an element and everything under it.
|
|
void toolXmlFree(ToolXmlT *node);
|
|
|
|
// An attribute's value, or NULL when the element has none of that name.
|
|
const char *toolXmlAttr(const ToolXmlT *node, const char *name);
|
|
|
|
// The element's first child of that name, or NULL.
|
|
const ToolXmlT *toolXmlChild(const ToolXmlT *node, const char *name);
|
|
|
|
#endif
|