The C
api.
Include xmq.h and compile xmq.c into your program, to parse, query, transform and print xmq, xml, html and json. This page is generated from xmq.h itself: the header is parsed with the ixml grammar ixml:lang/c and transformed with an xslq stylesheet.
scripts/generate_xmq_h_api_doc.sh
Examples:load_config_file.c create_dom.c create_html.c create_json.c default_namespace.c namespace_prefixes.c add_namespace.c generated_prefixes.c parse_with_ixml.c line_printf.c
Functions
xmqDetectContentTypeDetect the content type xmq/xml/html/json by examining a few leading non-whitespace words/characters.
XMQContentType xmqDetectContentType(const char *start, const char *stop);
Parameters
start- Points to the first byte of the buffer to scan.
stop- Points to the byte after the buffer.
Returns
The detected content type, XMQ_CONTENT_UNKNOWN if it could not be detected.
xmqParseErrorToStringTranslate an error code to a human readable string.
const char *xmqParseErrorToString(XMQStatus e);
Parameters
e- The error code.
Returns
A static string describing the error.
xmqNewParseCallbacksAllocate an empty parse callbacks structure.
XMQParseCallbacks *xmqNewParseCallbacks();
Returns
The new callbacks, free them with xmqFreeParseCallbacks.
xmqFreeParseCallbacksFree the parse callbacks structure.
void xmqFreeParseCallbacks(XMQParseCallbacks *cb);
Parameters
cb- The callbacks to free.
xmqSetupParseCallbacksColorizeTokensSet up the callbacks to colorize xmq input, without building a parse tree.
void xmqSetupParseCallbacksColorizeTokens(XMQParseCallbacks *state, XMQRenderFormat render_format);
Parameters
state- The callbacks to set up.
render_format- The format to colorize for, eg terminal or html.
xmqSetupParseCallbacksDebugTokensSet up the callbacks to print the location and type of each token, for debugging.
void xmqSetupParseCallbacksDebugTokens(XMQParseCallbacks *state);
Parameters
state- The callbacks to set up.
xmqSetupParseCallbacksDebugContentSet up the callbacks to print the decoded content of each token, for debugging.
void xmqSetupParseCallbacksDebugContent(XMQParseCallbacks *state);
Parameters
state- The callbacks to set up.
xmqTokenizeBufferTokenize a buffer with xmq content, invoking the callbacks of the parse state for each token.
bool xmqTokenizeBuffer(XMQParseState *state, const char *start, const char *stop);
Parameters
state- The parse state with the callbacks.
start- Points to the first byte of the buffer.
stop- Points to the byte after the buffer.
Returns
True if the buffer was tokenized without errors.
xmqTokenizeFileTokenize a file with xmq content, invoking the callbacks of the parse state for each token.
bool xmqTokenizeFile(XMQParseState *state, const char *file);
Parameters
state- The parse state with the callbacks.
file- The file to tokenize.
Returns
True if the file was tokenized without errors.
xmqTokenizeFileDescriptorTokenize xmq content read from a file descriptor.
bool xmqTokenizeFileDescriptor(XMQParseState *state, int fd);
Parameters
state- The parse state with the callbacks.
fd- The file descriptor to read from.
Returns
True if the content was tokenized without errors.
xmqNewParseStateCreate a parse state, used to tokenize xmq with your own callbacks.
XMQParseState *xmqNewParseState(XMQParseCallbacks *callbacks, XMQOutputSettings *settings);
Parameters
callbacks- The callbacks invoked for each token.
settings- The settings available to the callbacks.
Returns
The new parse state, free it with xmqFreeParseState.
xmqFreeParseStateFree the parse state.
void xmqFreeParseState(XMQParseState *state);
Parameters
state- The parse state to free.
xmqSetStateSourceNameSet the source name used in the error messages when parsing fails.
void xmqSetStateSourceName(XMQParseState *state, const char *source_name);
Parameters
state- The parse state.
source_name- The source name.
xmqStateErrnoGet the error code of a failed parse.
int xmqStateErrno(XMQParseState *state);
Parameters
state- The parse state.
Returns
The error as the integer value of an XMQStatus.
xmqStateErrorMsgGet a message explaining why a parse failed.
const char *xmqStateErrorMsg(XMQParseState *state);
Parameters
state- The parse state.
Returns
The error message, owned by the parse state.
xmqSetPrintAllParsesIXMLSet if all trees should be generated when an ixml parse is ambiguous.
void xmqSetPrintAllParsesIXML(XMQParseState *state, bool all_parses);
Parameters
state- The parse state.
all_parses- If true generate all possible trees.
xmqSetTryToRecoverIXMLSet if a failed ixml parse should try to recover.
void xmqSetTryToRecoverIXML(XMQParseState *state, bool try_recover);
Parameters
state- The parse state.
try_recover- If true try to recover a failed parse.
xmqNewDocCreate an empty document.
XMQReturnDoc xmqNewDoc();
Returns
The status and the document. If the status is XMQ_OK then the document is valid,
xmqSetDocSourceNameSet the source name used in the error messages when parsing fails.
void xmqSetDocSourceName(XMQDoc *doq, const char *source_name);
Parameters
doq- The document.
source_name- The source name.
xmqGetDocSourceNameGet the source name of the document, used in the error messages when parsing fails.
const char *xmqGetDocSourceName(XMQDoc *doq);
Parameters
doq- The document.
Returns
The source name, or NULL if none was set.
xmqGetOriginalContentTypeGet the content type (xmq, htmq, xml, html, json, text...) that the document was parsed from.
XMQContentType xmqGetOriginalContentType(XMQDoc *doq);
Parameters
doq- The document.
Returns
The original content type, if available.
xmqGetOriginalSizeGet the size of the content that the document was parsed from, ie the loaded file size.
size_t xmqGetOriginalSize(XMQDoc *doq);
Parameters
doq- The document.
Returns
The original size in bytes, if available.
xmqSetOriginalSizeOverride the original size of the document.
void xmqSetOriginalSize(XMQDoc *doq, size_t size);
Parameters
doq- The document.
size- The size in bytes.
xmqGetRootNodeGet the root node, suitable as the relative node for xmqForeachRel.
xmqSetDocTypeSet the doctype of the document.
xmqAddRootElementCreate a new root element.
XMQReturnNode xmqAddRootElement(XMQDoc *doq, const char *name, XMQNS ns);
Parameters
doq- The xmq document.
name- The name of the new element.
ns- The namespace setting.
Returns
The status and the new element.
xmqAddElementCreate a new element node below an existing element.
XMQReturnNode xmqAddElement(XMQDoc *doq, XMQNode *parent, const char *name, XMQNS ns);
Parameters
doq- The xmq document.
parent- The existing element.
name- The name of the new element.
ns- The namespace setting.
Returns
The status and the new element.
xmqAddElementWithAttrsCreate a new element node below an existing element with attributes.
XMQReturnNode xmqAddElementWithAttrs(XMQDoc *doq, XMQNode *parent, const char *name, XMQNS ns, XMQAttrList attrs);
Parameters
doq- The xmq document.
parent- The existing element.
name- The name of the new element.
ns- The namespace setting.
attrs- The attributes, see XMQ_ATTRS.
Returns
The status and the new element.
xmqMoveElementMove an element node somewhere else.
bool xmqMoveElement(XMQDoc *from_doq, XMQNode *from_parent, XMQNode *element, XMQDoc *to_doq, XMQNode *to_parent, XMQMoveTo where, XMQNode *sibling);
Parameters
from_doq- The xmq document to move from.
from_parent- The parent holding the element to be moved.
element- The element to be moved.
to_doq- The xmq document to move to, can be the same as from_doq.
to_parent- The new parent for the element.
where- Where to place the element below the new parent.
sibling- If where is in relation to a sibling, this is the sibling. Can be NULL if not needed.
Returns
True if the element was moved.
xmqAddKeyValueCreate a key value under an existing node.
XMQReturnNode xmqAddKeyValue(XMQDoc *doq, XMQNode *parent, const char *key, const char *value, XMQNS ns);
Parameters
doq- The xmq document.
parent- The parent in which the key value is created.
key- The key.
value- The value.
ns- The namespace setting.
Returns
The status and the new node.
xmqAddTextAdd text last in an existing node.
XMQStatus xmqAddText(XMQDoc *doq, XMQNode *parent, const char *text, size_t len);
Parameters
doq- The xmq document.
parent- The node to add the text to.
text- The text, utf8, does not need to be zero terminated.
len- The number of bytes of the text.
Returns
XMQ_OK if the text was added.
xmqHasAttributeCheck if an element has an attribute (without a namespace).
bool xmqHasAttribute(XMQNode *node, const char *name);
Parameters
node- The element.
name- The attribute name.
Returns
True if the attribute exists.
xmqContentMarkMark the end of the current content of a node.
XMQContentMark xmqContentMark(XMQNode *node);
Parameters
node- The node.
Returns
The mark, to be given to xmqWrapContent.
xmqWrapContentMove the content (children and attributes) added to the node after the mark into a new element, which is added last to the node.
XMQReturnNode xmqWrapContent(XMQDoc *doq, XMQNode *node, XMQContentMark mark, const char *name);
Parameters
doq- The xmq document.
node- The node.
mark- The mark from xmqContentMark on the same node.
name- The name of the new element.
Returns
The new element.
xmqAddKeyValueWithAttrsCreate a key value with attributes under an existing node.
XMQReturnNode xmqAddKeyValueWithAttrs(XMQDoc *doq, XMQNode *parent, const char *key, const char *value, XMQNS ns, XMQAttrList attrs);
Parameters
doq- The document.
parent- The parent in which the key value is created.
key- The key.
value- The value.
ns- The namespace setting.
attrs- The attributes, see XMQ_ATTRS.
Returns
The new node.
xmqSetAttributeCreate or update an attribute of an existing node.
XMQReturnAttr xmqSetAttribute(XMQDoc *doq, XMQNode *node, const char *name, const char *value, XMQNS ns);
Parameters
doq- The document.
node- The node to set the attribute on.
name- The attribute name.
value- The attribute value.
ns- The namespace setting.
Returns
The attribute.
xmqAddNamespaceAdd a prefixed namespace declaration to a node.
XMQStatus xmqAddNamespace(XMQDoc *doq, XMQNode *node, XMQNS ns);
Parameters
doq- The document.
node- The node in which the namespace declaration is put.
ns- The namespace, NS_HERE with the prefix encoded in the uri, eg NS_HERE("{drv}urn:myapp:driver").
Returns
XMQ_OK, or an error if the prefix is already taken.
xmqChangePrefixChange the prefix that was chosen automatically for a namespace.
XMQReturnString xmqChangePrefix(XMQDoc *doq, XMQNode *node, const char *ns_uri, const char *old_prefix, const char *new_prefix);
Parameters
doq- The document.
node- The node with the namespace declaration.
ns_uri- The namespace uri.
old_prefix- The current prefix.
new_prefix- The new prefix.
Returns
The status, XMQ_ERROR_PREFIX_EXISTS if the new prefix is already used.
xmqClearDocRemove all content from the document, making it empty.
void xmqClearDoc(XMQDoc *doc);
Parameters
doc- The document.
xmqFreeDocFree the document and all memory associated with it.
void xmqFreeDoc(XMQDoc *doc);
Parameters
doc- The document to free.
xmqParseFileParse a file and create the document, or read from stdin if file is NULL.
bool xmqParseFile(XMQDoc *doc, const char *file, const char *implicit_root, int flags);
Parameters
doc- The document to populate.
file- The file to parse, or NULL for stdin.
implicit_root- The implicit root, or NULL.
flags- The parse flags (XMQFlagBits), 0 for the defaults.
Returns
True if the parse succeeded, otherwise see xmqDocError.
xmqParseBufferParse a buffer and create the document.
bool xmqParseBuffer(XMQDoc *doc, const char *start, const char *stop, const char *implicit_root, int flags);
Parameters
doc- The document to populate.
start- Points to the first byte of the buffer.
stop- Points to the byte after the buffer.
implicit_root- The implicit root, or NULL.
flags- The parse flags (XMQFlagBits), 0 for the defaults.
Returns
True if the parse succeeded, otherwise see xmqDocError.
xmqParseReaderParse data fetched with a reader and create the document.
bool xmqParseReader(XMQDoc *doc, XMQReader *reader, void *reader_state, const char *implicit_root, int flags);
Parameters
doc- The document to populate.
reader- The reader that fetches the input data.
reader_state- The state passed to the reader.
implicit_root- The implicit root, or NULL.
flags- The parse flags (XMQFlagBits), 0 for the defaults.
Returns
True if the parse succeeded.
xmqInferMissingElementNamesRename anonymous elements (elements with name _ ) by inferring a name from the parent element: an anonymous child of an element named for example 'items' or 'branches' gets the name 'item' or 'branch' (the trailing 's' is dropped).
bool xmqInferMissingElementNames(XMQDoc *doq, const char *root_name);
Parameters
doq- The document to modify in place.
root_name- If not NULL and non-empty, and the root element is anonymous (_),
Returns
True if the document was processed.
xmqNewOutputSettingsAllocate output settings with everything set to zero.
XMQOutputSettings *xmqNewOutputSettings();
Returns
The new settings, free them with xmqFreeOutputSettings.
xmqFreeOutputSettingsFree the output settings.
void xmqFreeOutputSettings(XMQOutputSettings *os);
Parameters
os- The settings to free.
xmqSetAddIndentSet the number of spaces to indent each level when pretty printing.
void xmqSetAddIndent(XMQOutputSettings *os, int add_indent);
Parameters
os- The output settings to modify.
add_indent- The number of spaces per indentation level.
xmqSetCompactSet compact printing, the whole document on a single line with the whitespace between tokens minimized, eg a=('line one' 'line two')b=2
void xmqSetCompact(XMQOutputSettings *os, bool compact);
Parameters
os- The output settings to modify.
compact- If true print compact, if false pretty print.
xmqSetColorModeSet if and how the output is colorized when rendering to the terminal, html or tex.
void xmqSetColorMode(XMQOutputSettings *os, XMQColorMode color_mode);
Parameters
os- The output settings to modify.
color_mode- No color, colors for a dark or a light background, or automatic.
xmqSetTrueColorSet if the terminal supports truecolor (24 bit ansi colors), otherwise the colors are approximated with the 256 color palette.
void xmqSetTrueColor(XMQOutputSettings *os, bool truecolor);
Parameters
os- The output settings to modify.
truecolor- If true use 24 bit ansi color codes.
xmqSetPreferDoubleQuotesSet if quotes should use double quotes "..." instead of single quotes '...' when the content permits it.
void xmqSetPreferDoubleQuotes(XMQOutputSettings *os, bool prefer_double_quotes);
Parameters
os- The output settings to modify.
prefer_double_quotes- If true prefer double quotes.
xmqSetFinalNewlineSet if the output ends with a newline.
void xmqSetFinalNewline(XMQOutputSettings *os, bool final_nl);
Parameters
os- The output settings to modify.
final_nl- If true print a final newline.
xmqSetEscapeNewlinesSet if newlines inside quotes should be printed as the entity instead, eg ( 'line one' 'line two' ) instead of a multiline quote.
void xmqSetEscapeNewlines(XMQOutputSettings *os, bool escape_newlines);
Parameters
os- The output settings to modify.
escape_newlines- If true escape newlines.
xmqSetEscapeNon7bitSet if characters outside of 7 bit ascii should be printed as entities, eg Göteborg becomes ( 'G' ö 'teborg' ).
void xmqSetEscapeNon7bit(XMQOutputSettings *os, bool escape_non_7bit);
Parameters
os- The output settings to modify.
escape_non_7bit- If true escape non 7 bit characters.
xmqSetEscapeTabsSet if tabs inside quotes should be printed as the entity 	 instead.
void xmqSetEscapeTabs(XMQOutputSettings *os, bool escape_tabs);
Parameters
os- The output settings to modify.
escape_tabs- If true escape tabs.
xmqSetOutputFormatSet the format that xmqPrint prints the document in.
void xmqSetOutputFormat(XMQOutputSettings *os, XMQContentType output_format);
Parameters
os- The output settings to modify.
output_format- XMQ_CONTENT_XMQ, HTMQ, XML, HTML, JSON, YAML, TEXT or CLINES.
xmqSetOmitDeclSet if the xml declaration <?xml version="1.0" encoding="utf-8"?> should be left out when printing xml.
void xmqSetOmitDecl(XMQOutputSettings *os, bool omit_decl);
Parameters
os- The output settings to modify.
omit_decl- If true do not print the xml declaration.
xmqSetRenderFormatSet how xmq output is rendered: plain, or colorized for the terminal, html, htmq or tex.
void xmqSetRenderFormat(XMQOutputSettings *os, XMQRenderFormat render_to);
Parameters
os- The output settings to modify.
render_to- The render format.
xmqSetRenderThemeSet the theme used for rendering, a theme name with optional color overrides, eg lightbg:C=ff0000_U:AKV=00ffff.
void xmqSetRenderTheme(XMQOutputSettings *os, const char *theme_spec);
Parameters
os- The output settings to modify.
theme_spec- The theme specification, or NULL for the default theme.
xmqSetRenderRawSet if rendering should produce only the colorized content, without the surrounding page and style, eg only the pre element of render-html (--nostyle).
void xmqSetRenderRaw(XMQOutputSettings *os, bool render_raw);
Parameters
os- The output settings to modify.
render_raw- If true render only the content.
xmqSetRenderOnlyStyleSet if rendering should produce only the style, eg the css of render-html (--onlystyle).
void xmqSetRenderOnlyStyle(XMQOutputSettings *os, bool only_style);
Parameters
os- The output settings to modify.
only_style- If true render only the style.
xmqSetWriterContentSet the writer that receives the printed content.
void xmqSetWriterContent(XMQOutputSettings *os, XMQWriter content);
Parameters
os- The output settings to modify.
content- The writer function and its state.
xmqSetWriterErrorSet the writer that receives the error messages.
void xmqSetWriterError(XMQOutputSettings *os, XMQWriter error);
Parameters
os- The output settings to modify.
error- The writer function and its state.
xmqSetupPrintStdOutStdErrSet up the printer to print the content to stdout and the errors to stderr.
void xmqSetupPrintStdOutStdErr(XMQOutputSettings *ps);
Parameters
ps- The output settings to modify.
xmqSetupPrintFileSet up the printer to print to a file.
void xmqSetupPrintFile(XMQOutputSettings *ps, const char *file);
Parameters
ps- The output settings to modify.
file- The file to print to.
xmqSetupPrintFileDescriptorSet up the printer to print to a file descriptor.
void xmqSetupPrintFileDescriptor(XMQOutputSettings *ps, int fd);
Parameters
ps- The output settings to modify.
fd- The file descriptor to print to.
xmqSetupPrintMemorySet up the printer to print to a dynamically allocated memory buffer.
void xmqSetupPrintMemory(XMQOutputSettings *ps, char **start, char **stop);
Parameters
ps- The output settings to modify.
start- Receives the start of the output.
stop- Receives the end of the output.
xmqSetupPrintSkipSet where to store the number of leading bytes of the memory output to skip, eg the xml declaration when it should be omitted.
void xmqSetupPrintSkip(XMQOutputSettings *ps, size_t *skip);
Parameters
ps- The output settings to modify.
skip- Receives the number of bytes to skip.
xmqPrintPrint the document according to the output settings.
void xmqPrint(XMQDoc *doc, XMQOutputSettings *settings);
Parameters
doc- The document to print.
settings- The output settings.
xmqAnnotateOffsetsAdd an attribute to each element with the offset of its text content.
void xmqAnnotateOffsets(XMQDoc *doc, const char *attribute_name, const char *ns);
Parameters
doc- The document to modify.
attribute_name- The name of the attribute to add.
ns- The namespace of the attribute, or NULL.
xmqTrimWhitespaceTrim the whitespace of the text nodes and comments in the document.
void xmqTrimWhitespace(XMQDoc *doc, int flags);
Parameters
doc- The document to modify.
flags- The trim flags, eg XMQ_FLAG_TRIM_HEURISTIC.
xmqCompactQuoteCreate a compact single line quote that safely stores the content.
char *xmqCompactQuote(const char *content);
Parameters
content- The string to quote.
Returns
A new NUL terminated string that the caller frees.
xmqDocErrorGet the error message of a failed parse or operation on the document.
const char *xmqDocError(XMQDoc *doc);
Parameters
doc- The document.
Returns
The error message, freed together with the document.
xmqDocErrnoGet the error status of a failed parse or operation on the document.
xmqGetNameGet the name of a node, eg the element name.
const char *xmqGetName(XMQNode *node);
Parameters
node- The node.
Returns
The name.
xmqGetContentGet the content of a node.
const char *xmqGetContent(XMQNode *node);
Parameters
node- The node.
Returns
The content, or NULL.
xmqGetNodeTypeGet the kind of a node, eg element, text or comment.
XMQNodeType xmqGetNodeType(XMQNode *node);
Parameters
node- The node.
Returns
The node type.
xmqGetDocNodeGet the document node, whose children are the top level nodes (the root element, comments, processing instructions and the doctype).
xmqGetParentGet the parent node.
xmqFirstChildGet the first child node.
xmqLastChildGet the last child node.
xmqNextSiblingGet the next sibling node.
xmqPrevSiblingGet the previous sibling node.
xmqGetNamespaceUriGet the namespace uri of an element.
const char *xmqGetNamespaceUri(XMQNode *node);
Parameters
node- The element.
Returns
The namespace uri, or NULL if it has no namespace.
xmqGetNamespacePrefixGet the namespace prefix of an element.
const char *xmqGetNamespacePrefix(XMQNode *node);
Parameters
node- The element.
Returns
The prefix, or NULL if it has no prefix.
xmqGetLineGet the line number in the source where the node was found.
int xmqGetLine(XMQNode *node);
Parameters
node- The node.
Returns
The line number, or 0 if unknown.
xmqFirstAttrGet the first attribute of an element.
XMQAttr *xmqFirstAttr(XMQNode *node);
Parameters
node- The element.
Returns
The first attribute, or NULL if there are no attributes.
xmqNextAttrGet the next attribute of the same element.
xmqGetAttrFind an attribute by its name (without prefix), regardless of namespace, like xmqHasAttribute.
xmqGetAttrNameGet the name of an attribute, without prefix.
const char *xmqGetAttrName(XMQAttr *attr);
Parameters
attr- The attribute.
Returns
The name.
xmqGetAttrValueGet the value of an attribute.
const char *xmqGetAttrValue(XMQAttr *attr);
Parameters
attr- The attribute.
Returns
The value, or NULL.
xmqGetAttrNamespaceUriGet the namespace uri of an attribute.
const char *xmqGetAttrNamespaceUri(XMQAttr *attr);
Parameters
attr- The attribute.
Returns
The namespace uri, or NULL if it has no namespace.
xmqGetAttrNamespacePrefixGet the namespace prefix of an attribute.
const char *xmqGetAttrNamespacePrefix(XMQAttr *attr);
Parameters
attr- The attribute.
Returns
The prefix, or NULL if it has no prefix.
xmqGetAttrOwnerGet the element that an attribute belongs to.
xmqSetContentSet the content of a node, replacing its children with the text.
void xmqSetContent(XMQNode *node, const char *raw_content);
Parameters
node- The node.
raw_content- The new content.
xmqGetNodeGet the first node that matches the xpath.
xmqGetNodeRelGet the first node that matches the xpath, evaluated relative to a node.
XMQNode *xmqGetNodeRel(XMQDoc *doc, const char *xpath, XMQNode *relative);
Parameters
doc- The document.
xpath- The xpath to search for.
relative- The node the xpath is evaluated from.
Returns
The node, or NULL if nothing matches.
xmqGetIntGet the content of the first node that matches the xpath as a 32 bit signed integer.
int32_t xmqGetInt(XMQDoc *doc, const char *xpath);
Parameters
doc- The document.
xpath- The xpath to search for.
Returns
The integer, or 0 if nothing matches.
xmqGetIntRelGet the content of the first node that matches the xpath, evaluated relative to a node, as a 32 bit signed integer.
int32_t xmqGetIntRel(XMQDoc *doc, const char *xpath, XMQNode *relative);
Parameters
doc- The document.
xpath- The xpath to search for.
relative- The node the xpath is evaluated from.
Returns
The integer, or 0 if nothing matches.
xmqGetLongGet the content of the first node that matches the xpath as a 64 bit signed integer.
int64_t xmqGetLong(XMQDoc *doc, const char *xpath);
Parameters
doc- The document.
xpath- The xpath to search for.
Returns
The integer, or 0 if nothing matches.
xmqGetLongRelGet the content of the first node that matches the xpath, evaluated relative to a node, as a 64 bit signed integer.
int64_t xmqGetLongRel(XMQDoc *doc, const char *xpath, XMQNode *relative);
Parameters
doc- The document.
xpath- The xpath to search for.
relative- The node the xpath is evaluated from.
Returns
The integer, or 0 if nothing matches.
xmqGetDoubleGet the content of the first node that matches the xpath as a double.
double xmqGetDouble(XMQDoc *doc, const char *xpath);
Parameters
doc- The document.
xpath- The xpath to search for.
Returns
The double, or 0 if nothing matches.
xmqGetDoubleRelGet the content of the first node that matches the xpath, evaluated relative to a node, as a double.
double xmqGetDoubleRel(XMQDoc *doc, const char *xpath, XMQNode *relative);
Parameters
doc- The document.
xpath- The xpath to search for.
relative- The node the xpath is evaluated from.
Returns
The double, or 0 if nothing matches.
xmqGetStringGet the content of the first node that matches the xpath as a string, eg the value of a key=value.
const char *xmqGetString(XMQDoc *doc, const char *xpath);
Parameters
doc- The document.
xpath- The xpath to search for.
Returns
The content, owned by the document, or NULL if nothing matches.
xmqGetStringRelGet the content of the first node that matches the xpath, evaluated relative to a node, as a string, eg the value of a key=value.
const char *xmqGetStringRel(XMQDoc *doc, const char *xpath, XMQNode *relative);
Parameters
doc- The document.
xpath- The xpath to search for.
relative- The node the xpath is evaluated from.
Returns
The content, owned by the document, or NULL if nothing matches.
xmqForeachCall a function for each node that matches the xpath.
int xmqForeach(XMQDoc *doq, const char *xpath, XMQNodeCallback cb, void *user_data);
Parameters
doq- The document.
xpath- The xpath.
cb- The function to call for each node, or NULL to only count.
user_data- The user data passed to the function.
Returns
The number of matching nodes.
xmqForeachRelCall a function for each node that matches the xpath, evaluated relative to a node.
int xmqForeachRel(XMQDoc *doq, const char *xpath, XMQNodeCallback cb, void *user_data, XMQNode *relative);
Parameters
doq- The document.
xpath- The xpath.
cb- The function to call for each node, or NULL to only count.
user_data- The user data passed to the function.
relative- The node the xpath is evaluated from.
Returns
The number of matching nodes.
xmqReplaceEntityReplace each reference to an entity with a text.
int xmqReplaceEntity(XMQDoc *doq, const char *entity, const char *content);
Parameters
doq- The document.
entity- The entity name.
content- The text to insert.
Returns
The number of replacements.
xmqReplaceEntityWithNodeReplace each reference to an entity with a copy of a node from another document.
int xmqReplaceEntityWithNode(XMQDoc *doq, const char *entity, XMQDoc *idoq, XMQNode *inode);
Parameters
doq- The document.
entity- The entity name.
idoq- The document with the node to insert.
inode- The node to insert.
Returns
The number of replacements.
xmqExpandEntitiesExpand the entities declared in the doctype.
XMQStatus xmqExpandEntities(XMQDoc *doq);
Parameters
doq- The document.
Returns
XMQ_OK, or XMQ_ERROR_ENTITY_EXPANSION with the message in xmqDocError.
xmqVersionGet the version of this library.
const char *xmqVersion();
Returns
The version string.
xmqFeaturesGet the optional parts compiled into this library, space separated, from "xmq-printing json yaml xslt xsd ixml html".
const char *xmqFeatures();
Returns
The compiled in parts.
xmqSetVerboseEnable or disable verbose logging.
void xmqSetVerbose(bool e);
Parameters
e- True to enable.
xmqSetProgressEnable or disable printing the progress on stderr, eg while parsing a large input with ixml.
void xmqSetProgress(bool e);
Parameters
e- True to enable.
xmqSetDebugEnable or disable debug logging.
void xmqSetDebug(bool e);
Parameters
e- True to enable.
xmqSetTraceEnable or disable trace logging.
void xmqSetTrace(bool e);
Parameters
e- True to enable.
xmqLogFilterOnly log the debug and trace messages that start with a prefix, eg "xmq=".
void xmqLogFilter(const char *log_filter);
Parameters
log_filter- The prefix, or NULL to log all messages.
xmqDebuggingCheck if debug logging is enabled.
bool xmqDebugging();
Returns
True if enabled.
xmqTracingCheck if trace logging is enabled.
bool xmqTracing();
Returns
True if enabled.
xmqSetLogHumanReadableSet if the verbose, debug and trace logging is human readable.
void xmqSetLogHumanReadable(bool e);
Parameters
e- True for human readable.
xmqLoggingXMQCheck if logging is in xmq.
bool xmqLoggingXMQ();
Returns
True if logging is in xmq.
xmqParseBufferWithTypeParse a buffer with a given content type and create the document.
bool xmqParseBufferWithType(XMQDoc *doc, const char *start, const char *stop, const char *implicit_root, XMQContentType ct, int flags);
Parameters
doc- The document to populate.
start- Points to the first byte of the buffer.
stop- Points to the byte after the buffer.
implicit_root- The implicit root, or NULL.
ct- The content type, or XMQ_CONTENT_DETECT to detect it.
flags- The parse flags (XMQFlagBits), 0 for the defaults.
Returns
True if the parse succeeded, otherwise see xmqDocError.
xmqParseFileWithTypeParse a file with a given content type and create the document, or read from stdin if file is NULL.
bool xmqParseFileWithType(XMQDoc *doc, const char *file, const char *implicit_root, XMQContentType ct, int flags);
Parameters
doc- The document to populate.
file- The file to parse, or NULL for stdin.
implicit_root- The implicit root, or NULL.
ct- The content type, or XMQ_CONTENT_DETECT to detect it.
flags- The parse flags (XMQFlagBits), 0 for the defaults.
Returns
True if the parse succeeded, otherwise see xmqDocError.
xmqParseBufferWithIXMLParse a buffer with an ixml grammar and create the document.
bool xmqParseBufferWithIXML(XMQDoc *doc, const char *start, const char *stop, XMQDoc *ixml_grammar, int flags);
Parameters
doc- The document to populate.
start- Points to the first byte of the buffer.
stop- Points to the byte after the buffer.
ixml_grammar- The grammar, a document parsed with XMQ_CONTENT_IXML.
flags- The parse flags (XMQFlagBits), 0 for the defaults.
Returns
True if the parse succeeded, otherwise see xmqDocError.
xmqTakeIXMLTraceTake the trace of the last parse of doc with xmqParseBufferWithIXML and the flag XMQ_FLAG_IXML_TRACE.
XMQDoc *xmqTakeIXMLTrace(XMQDoc *doc);
Parameters
doc- The parsed document.
Returns
The trace document, owned by the caller who frees it with xmqFreeDoc, or NULL.
xmqIXMLFromDocGet the ixml text of a grammar in xml form, ie the parse tree of the grammar with the ixml grammar, eg ixml{rule(name=S){alt{literal(string=a)}}}, read from xml, xmq or json.
char *xmqIXMLFromDoc(XMQDoc *grammar, char **error);
Parameters
grammar- The grammar in xml form.
error- Receives an error message, that the caller frees, if NULL is returned.
Returns
The ixml text, that the caller frees, or NULL if the document is not such a grammar.
xmqTakeIXMLCompletionsTake what could follow the input of the last parse of doc with xmqParseBufferWithIXML and the flag XMQ_FLAG_IXML_COMPLETE.
char *xmqTakeIXMLCompletions(XMQDoc *doc);
Parameters
doc- The parsed document.
Returns
The completions, that the caller frees, or NULL if the input could not be parsed up to its end.
xmqParseFileWithIXMLParse a file with an ixml grammar and create the document, or read from stdin if file is NULL.
bool xmqParseFileWithIXML(XMQDoc *doc, const char *file, XMQDoc *ixml_grammar, int flags);
Parameters
doc- The document to populate.
file- The file to parse, or NULL for stdin.
ixml_grammar- The grammar, a document parsed with XMQ_CONTENT_IXML.
flags- The parse flags (XMQFlagBits), 0 for the defaults.
Returns
True if the parse succeeded, otherwise see xmqDocError.
xmqSetupDefaultColorsSet up the colors of the output settings from the theme and the color mode.
void xmqSetupDefaultColors(XMQOutputSettings *settings);
Parameters
settings- The output settings to modify.
xmqOverrideSettingsChange the strings printed for indentation and explicit whitespace.
void xmqOverrideSettings(XMQOutputSettings *settings, const char *indentation_space, const char *explicit_space, const char *explicit_tab, const char *explicit_cr, const char *explicit_nl);
Parameters
settings- The output settings to modify.
indentation_space- The indentation, if NULL use " ".
explicit_space- An explicit space, if NULL use " ".
explicit_tab- An explicit tab, if NULL use "\t".
explicit_cr- An explicit carriage return, if NULL use "\r".
explicit_nl- An explicit newline, if NULL use "\n".
xmqRenderHtmlSettingsSet the id and class of the pre element of the rendered html.
void xmqRenderHtmlSettings(XMQOutputSettings *settings, const char *use_id, const char *use_class);
Parameters
settings- The output settings to modify.
use_id- The id of the pre element, or NULL.
use_class- The class of the pre element, or NULL.
xmqOverrideColorChange the color strings of a syntax element.
void xmqOverrideColor(XMQOutputSettings *settings, const char *render_style, XMQColorName cn, const char *pre, const char *post, const char *ns);
Parameters
settings- The output settings to modify.
render_style- The render style, "" for the default.
cn- The syntax element to change the color for.
pre- The string printed before the element.
post- The string printed after the element.
ns- The color of the namespace prefix.
xmqNewLineConfigAllocate a line configuration with the defaults, used to generate single line xmq for logging.
XMQLineConfig *xmqNewLineConfig();
Returns
The new line configuration, free it with xmqFreeLineConfig.
xmqFreeLineConfigFree the line configuration.
void xmqFreeLineConfig(XMQLineConfig *lc);
Parameters
lc- The line configuration to free.
xmqSetLineHumanReadableSet if the generated log lines should be more human readable.
void xmqSetLineHumanReadable(XMQLineConfig *lc, bool enable);
Parameters
lc- The line configuration.
enable- True for more human readable lines.
xmqLineDocGenerate a compact single line xmq string, without any newlines, from a document, for logging.
char *xmqLineDoc(XMQLineConfig *lc, XMQDoc *doc);
Parameters
lc- The line configuration.
doc- The document.
Returns
A new string that the caller frees.
xmqLinePrintfGenerate a compact single line xmq string, without any newlines, for logging.
char *xmqLinePrintf(XMQLineConfig *lc, const char *element_name, ...);
Parameters
lc- The line configuration.
element_name- The element name, eg "car{", followed by key, format and value arguments.
Returns
A new string that the caller frees.
xmqLineVPrintfThe same as xmqLinePrintf but with the arguments as a va_list.
char *xmqLineVPrintf(XMQLineConfig *lc, const char *element_name, va_list ap);
Parameters
lc- The line configuration.
element_name- The element name, eg "car{", followed by the arguments in ap.
ap- The key, format and value arguments, see xmqLinePrintf.
Returns
A new string that the caller must free.
xmqCompileXsltCompile an xslt stylesheet.
XMQReturnXslt xmqCompileXslt(XMQDoc *stylesheet, XMQXsltSettings *settings);
Parameters
stylesheet- The stylesheet document.
settings- The loader and message settings, or NULL for the defaults.
Returns
The status and the compiled stylesheet. On failure the status is XMQ_ERROR_XSLT_COMPILE
xmqSetXsltParamSet a top level parameter of the stylesheet.
void xmqSetXsltParam(XMQXslt *xslt, const char *name, const char *value, bool is_xpath);
Parameters
xslt- The compiled stylesheet.
name- The parameter name.
value- The value.
is_xpath- If true the value is an xpath expression (like --param), otherwise a string (like --stringparam).
xmqTransformApply the stylesheet to a document.
XMQReturnDoc xmqTransform(XMQXslt *xslt, XMQDoc *doc);
Parameters
xslt- The compiled stylesheet.
doc- The document to transform.
Returns
The status and the result document. On failure the status is XMQ_ERROR_XSLT_TRANSFORM
xmqSaveXsltResultSerialize a result of xmqTransform as the xsl:output of the stylesheet asks for (method, encoding, indent, doctype, xml declaration), like libxslt xsltSaveResultToString.
char *xmqSaveXsltResult(XMQXslt *xslt, XMQDoc *result, size_t *len);
Parameters
xslt- The compiled stylesheet.
result- The result of xmqTransform.
len- Receives the length, the string may contain zeros for UTF-16.
Returns
A new string that the caller frees.
xmqFreeXsltFree a compiled stylesheet.
void xmqFreeXslt(XMQXslt *xslt);
Parameters
xslt- The compiled stylesheet to free.
xmqCompileXsdCompile an xsd schema.
XMQReturnXsd xmqCompileXsd(XMQDoc *schema, XMQXsdSettings *settings);
Parameters
schema- The schema document.
settings- The loader and message settings, or NULL for the defaults.
Returns
The status and the compiled schema. On failure the status is XMQ_ERROR_XSD_COMPILE
xmqSetXsdMessageCallbackChange where the messages of xmqValidate go.
void xmqSetXsdMessageCallback(XMQXsd *xsd, XMQXsdMessageCallback callback, void *user_data);
Parameters
xsd- The compiled schema.
callback- The function that receives the messages, or NULL to print them on stderr.
user_data- The user data passed to the callback.
xmqValidateValidate a document against a schema.
XMQStatus xmqValidate(XMQXsd *xsd, XMQDoc *doc);
Parameters
xsd- The compiled schema.
doc- The document to validate.
Returns
XMQ_OK if it is valid, XMQ_ERROR_XSD_INVALID if it is not (the messages are also available
xmqFreeXsdFree a compiled schema.
Types
XMQDocOpaque structure storing a document.
typedef struct XMQDoc XMQDoc;
XMQNodeOpaque structure storing a node in the document.
typedef struct XMQNode XMQNode;
XMQAttrOpaque structure storing an attribute in the document.
typedef struct XMQAttr XMQAttr;
XMQParseStateAn opaque structure to maintain the parse state and the list of callbacks to be invoked when parsing xmq.
typedef struct XMQParseState XMQParseState;
XMQParseCallbacksStore your own parse callbacks into this structure and register it with the XMQParseState.
typedef struct XMQParseCallbacks XMQParseCallbacks;
XMQOutputSettingsOpaque structure storing a output settings when printing xmq, xml or json.
typedef struct XMQOutputSettings XMQOutputSettings;
XMQReaderA reader that the xmq parser invokes to fetch more data.
typedef struct XMQReader XMQReader;
Members
void *reader_state |
The reader_state is passed to the read function. |
size_t (*read)(void *reader_state, char *start, char *stop) |
The function to be invoked from the parser to fetch more data to parse. |
XMQWriteYou can pass your own xmq_writer to the printer routines to do your own final output.
typedef bool (*XMQWrite)(void *writer_state, const char *start, const char *stop);
Parameters
writer_state- Your own writer_state supplied to the printing function.
start- Start of buffer to write.
stop- Points to byte after buffer to write. If NULL then assume start is null terminated.
XMQWriterThe xmq printer uses the writer to write data supplied from a buffer (start <= i < stop).
typedef struct XMQWriter XMQWriter;
Members
void *writer_state |
The writer_state is passed to the write function. |
XMQWrite write |
The function to be invoked from the printer to write output data. |
XMQNodeCallbackThe function type which is called by foreach functions.
typedef XMQProceed (*XMQNodeCallback)(XMQDoc *doc, XMQNode *node, void *user_data);
Parameters
doc- The document being processed.
node- The node triggering the callback.
user_data- The user data supplied to for_each.
XMQReturnDocThe status and the document returned by a function that creates a document.
XMQReturnNodeThe status and the node returned by a function that creates a node.
XMQReturnAttrThe status and the attribute returned by a function that creates an attribute.
XMQReturnStringThe status and a string, that the caller frees, returned by a function.
typedef struct XMQReturnString XMQReturnString;
Members
XMQStatus status |
|
char *string |
XMQReturnConstStringThe status and a string, owned by the library, returned by a function.
typedef struct XMQReturnConstString XMQReturnConstString;
Members
XMQStatus status |
|
const char *string |
XMQLineConfigOpaque structure with the settings used to generate single line xmq for logging, see xmqNewLineConfig and xmqLinePrintf.
typedef struct XMQLineConfig XMQLineConfig;
XMQAddAttrAn attribute to add, a name and a value, see XMQ_ATTRS.
typedef struct XMQAddAttr XMQAddAttr;
Members
const char *name |
|
const char *value |
XMQAttrListA list of attributes to add, created with XMQ_ATTRS.
typedef struct XMQAttrList XMQAttrList;
Members
const XMQAddAttr *array |
|
size_t count |
XMQNSThe namespace setting of a new element or attribute, created with NS_NONE, NS_PARENT, NS_HERE(uri) or NS_ANCESTOR(uri).
typedef struct XMQNS XMQNS;
Members
NamespaceAction action |
|
const char *uri |
XMQContentMarkA position at the end of the current content (children and attributes) of a node, used by xmqWrapContent.
typedef struct XMQContentMark XMQContentMark;
Members
void *child |
|
size_t text_len |
|
void *attr |
XMQXsltA compiled XSLT 1.0 stylesheet.
typedef struct XMQXslt XMQXslt;
XMQReturnXsltThe status and the compiled stylesheet returned by xmqCompileXslt.
XMQXsltLoaderLoad the document at uri for xsl:import, xsl:include and document(), return NULL if it cannot be loaded.
typedef XMQDoc *(*XMQXsltLoader)(void *user_data, const char *uri);
XMQXsltMessageCallbackReceives the messages of compilation and transformation (errors, warnings, xsl:message).
typedef void (*XMQXsltMessageCallback)(void *user_data, const char *message);
XMQXsltSettingsThe settings for compiling a stylesheet, how to load imported files and where the messages go.
typedef struct XMQXsltSettings XMQXsltSettings;
Members
XMQXsltLoader loader |
NULL loads the files with xmqParseFileWithType (content detection, no trimming). |
void *loader_user_data |
|
XMQXsltMessageCallback message_callback |
NULL prints the messages on stderr (like libxslt). |
void *message_user_data |
XMQXsdA compiled XSD 1.0 schema.
typedef struct XMQXsd XMQXsd;
XMQReturnXsdThe status and the compiled schema returned by xmqCompileXsd.
XMQXsdLoaderLoad the schema document at uri for xs:include, xs:import and xs:redefine, return NULL if it cannot be loaded.
typedef XMQDoc *(*XMQXsdLoader)(void *user_data, const char *uri);
XMQXsdMessageCallbackReceives the messages of compilation and validation, exactly as libxml2 formats them for its plain error callbacks.
typedef void (*XMQXsdMessageCallback)(void *user_data, const char *message, bool is_warning);
XMQXsdSettingsThe settings for compiling a schema, how to load included files and where the messages go.
typedef struct XMQXsdSettings XMQXsdSettings;
Members
XMQXsdLoader loader |
NULL reads the files and parses them as xml with entities substituted (like libxml2). |
void *loader_user_data |
|
XMQXsdMessageCallback message_callback |
NULL prints the messages on stderr in the libxml2 format (file:line: element x: ...). |
void *message_user_data |
Enums
XMQColorModeSpecifies the color mode when rendering output that can be colorized (terminal, html and tex).
typedef enum { … } XMQColorMode;
Values
XMQ_MONO |
0 | Render without any color. Output is plain monochrome. |
XMQ_BG_DARK |
1 | Render with color, assuming a dark background. The dark background mode is forced. |
XMQ_BG_LIGHT |
2 | Render with color, assuming a light background. The light background mode is forced. |
XMQ_BG_AUTO |
3 | Render with color and decide the background automatically, defaulting to a dark background. For html this means the rendered page follows the browser dark/light mode preference. |
XMQContentTypeSpecify the file/buffer content type both for input and for output.
typedef enum { … } XMQContentType;
Values
XMQ_CONTENT_UNKNOWN |
0 | Unknown buffer content. |
XMQ_CONTENT_DETECT |
1 | Try to detect buffer content, is it xmq, xml or json? |
XMQ_CONTENT_XMQ |
2 | Content is xmq. |
XMQ_CONTENT_HTMQ |
3 | Content is htmq. |
XMQ_CONTENT_XML |
4 | Content is xml. |
XMQ_CONTENT_HTML |
5 | Content is html. |
XMQ_CONTENT_JSON |
6 | Content is json. |
XMQ_CONTENT_IXML |
7 | Content is ixml. |
XMQ_CONTENT_TEXT |
8 | Content is text. |
XMQ_CONTENT_CLINES |
9 | Cline content looks like: xpath="c-escaped string" |
XMQ_CONTENT_YAML |
10 | Content is YAML. |
XMQRenderFormatXMQRenderFormat decides how to format the xmq output: PLAIN, or for human consumption in TERMINAL, HTML, HTMQ, TEX.
typedef enum { … } XMQRenderFormat;
Values
XMQ_RENDER_PLAIN |
0 | Normal output for data storage. |
XMQ_RENDER_TERMINAL |
1 | Colorize output using ansi codes. |
XMQ_RENDER_HTML |
2 | Colorize output using html tags. |
XMQ_RENDER_HTMQ |
3 | Colorize output using htmq tags. |
XMQ_RENDER_TEX |
4 | Colorize using latex. |
XMQFlagBitsThe flag bits specify by the parser builds the document.
typedef enum { … } XMQFlagBits;
Values
XMQ_FLAG_TRIM_NONE |
1 | Do not trim any whitespace. Only relevant when parsing xml. |
XMQ_FLAG_TRIM_HEURISTIC |
2 | Remove leading/ending whitespace, but try to keep significant, remove incidental indentation. |
XMQ_FLAG_TRIM_EXACT |
4 | Not implemented. |
XMQ_FLAG_NOMERGE |
8 | Do not merge adjacent text nodes and character entity nodes. |
XMQ_FLAG_IXML_ALL_PARSES |
16 | When ixml parse is ambiguous generate all parses. |
XMQ_FLAG_IXML_TRY_TO_RECOVER |
32 | When ixml parse fails, try to recover. |
XMQ_FLAG_IXML_FAIL_SILENT |
64 | If the ixml parse fails generate an empty document and no errors. |
XMQ_FLAG_IXML_TRACE |
128 | Record a trace of the ixml parse (the grammar, the Earley items and the tree), see xmqTakeIXMLTrace. |
XMQ_FLAG_IXML_COMPLETE |
256 | Find what could follow the input, for completion, see xmqTakeIXMLCompletions. |
XMQColorNameXMQColorName is used to color the output when pretty printing xmq.
typedef enum { … } XMQColorName XMQColorName;
Values
XMQ_COLOR_C |
Comment. | |
XMQ_COLOR_Q |
Quote. | |
XMQ_COLOR_E |
Entity. | |
XMQ_COLOR_NS |
Name Space (both for element and attribute). | |
XMQ_COLOR_EN |
Element name. | |
XMQ_COLOR_EK |
Element key. | |
XMQ_COLOR_EKV |
Element key value. | |
XMQ_COLOR_AK |
Attribute key. | |
XMQ_COLOR_AKV |
Attribute key value. | |
XMQ_COLOR_CP |
Compound Parentheses. | |
XMQ_COLOR_NSD |
Name Space Declaration xmlns. | |
XMQ_COLOR_UW |
Unicode whitespace. | |
XMQ_COLOR_XLS |
Override xls prefixed element names with this color. |
XMQMoveToXMQMoveTo decides where a node is moved to, in a new parent element and potentially in relation to another sibling node.
typedef enum { … } XMQMoveTo;
Values
XMQ_MOVE_FIRST |
0 | Place the element first in the parents list of childrens. |
XMQ_MOVE_LAST |
1 | Place the element last in the parents list of children. |
XMQ_MOVE_BEFORE |
2 | Place the element before the element referenced. |
XMQ_MOVE_AFTER |
3 | Place the element after the element referenced. |
XMQProceedThe XMQProceed is used to proceed or stop when iterating over xmq nodes.
typedef enum { … } XMQProceed;
Values
XMQ_CONTINUE |
Return XMQ_CONTINUE to continue iterating over xmq nodes. | |
XMQ_STOP |
Return XMQ_STOP to stop iterating. |
XMQStatusThe xmq functions return OK or error values using the XMQStatus.
typedef enum { … } XMQStatus;
Values
XMQ_OK |
0 | No error. |
XMQ_ERROR_CANNOT_READ_FILE |
1 | File not found or cannot be opened for reading. |
XMQ_ERROR_OOM |
2 | Out of memory. |
XMQ_ERROR_NOT_XMQ |
3 | Expected xmq but auto detect sees early that it is not xmq. |
XMQ_ERROR_QUOTE_NOT_CLOSED |
4 | An xmq quote is not closed, ie single quotes are missing. |
XMQ_ERROR_ENTITY_NOT_CLOSED |
5 | An entity is missing the semicolon. |
XMQ_ERROR_COMMENT_NOT_CLOSED |
6 | A comment has not been closed. |
XMQ_ERROR_COMMENT_CLOSED_WITH_TOO_MANY_SLASHES |
7 | A comment close is not balanced. |
XMQ_ERROR_BODY_NOT_CLOSED |
8 | A body is missing a closing brace. |
XMQ_ERROR_ATTRIBUTES_NOT_CLOSED |
9 | The attribute list is missing the closing parentheses. |
XMQ_ERROR_COMPOUND_NOT_CLOSED |
10 | Compound content is missing the closing double parentheses. |
XMQ_ERROR_COMPOUND_MAY_NOT_CONTAIN |
11 | Compound content may only contains quotes and entities. |
XMQ_ERROR_QUOTE_CLOSED_WITH_TOO_MANY_QUOTES |
12 | Too many closing single quotes. |
XMQ_ERROR_UNEXPECTED_CLOSING_BRACE |
13 | An unexpected closing brace. |
XMQ_ERROR_EXPECTED_CONTENT_AFTER_EQUALS |
14 | Expected a value after equals. |
XMQ_ERROR_UNEXPECTED_TAB |
15 | Tabs are not permitted as token separators. |
XMQ_ERROR_INVALID_CHAR |
16 | An invalid character found. |
XMQ_ERROR_BAD_DOCTYPE |
17 | The doctype could not be parsed. |
XMQ_ERROR_JSON_INVALID_ESCAPE |
18 | An invalid json escape sequence. |
XMQ_ERROR_JSON_INVALID_CHAR |
19 | An invalid json character. |
XMQ_ERROR_CANNOT_HANDLE_XML |
20 | The XMl parser has been left out to shrink code size. |
XMQ_ERROR_CANNOT_HANDLE_HTML |
21 | The HTML parser has been left out to shrink code size. |
XMQ_ERROR_CANNOT_HANDLE_JSON |
22 | The JSON parser has been left out to shrink code size. |
XMQ_ERROR_EXPECTED_XMQ |
23 | Expecte xmq but was given something else. |
XMQ_ERROR_EXPECTED_HTMQ |
24 | Expecte htmq but was given something else. |
XMQ_ERROR_EXPECTED_XML |
25 | Expecte xml but was given something else. |
XMQ_ERROR_EXPECTED_HTML |
26 | Expecte html but was given something else. |
XMQ_ERROR_EXPECTED_JSON |
27 | Expecte json but was given something else. |
XMQ_ERROR_PARSING_XML |
28 | Error while parsing xml. |
XMQ_ERROR_PARSING_HTML |
29 | Error while parsing html. |
XMQ_ERROR_VALUE_CANNOT_START_WITH |
30 | A value after a key cannot start with comments or equals. |
XMQ_ERROR_INVALID_NAMESPACE_URI |
31 | Not a proper uri for a namespace. |
XMQ_ERROR_INVALID_NAMESPACE_PREFIX |
32 | Not a proper prefix for a namespace. |
XMQ_ERROR_NAMESPACE_PREFIX_ALREADY_TAKEN |
33 | When adding a new namespace with a prefix, the prefix has already been used. |
XMQ_ERROR_BAD_RANGE |
35 | Pointer errors to buffers are wrong. |
XMQ_ERROR_BAD_VALUE |
36 | Invalid enums provided or other bad input to functions. |
XMQ_ERROR_XML_FRAGMENT_NOT_CLOSED |
37 | An embedded xml fragment inside an xmq document is not closed. |
XMQ_ERROR_ENTITY_EXPANSION |
38 | An entity could not be expanded: a loop, too deep nesting, too large expansion or malformed replacement text. |
XMQ_ERROR_INVALID_UTF8 |
39 | The input is not valid UTF-8. |
XMQ_ERROR_TOO_DEEP |
40 | The elements, objects or arrays are nested deeper than XMQ_MAX_NESTING_DEPTH. |
XMQ_ERROR_IXML_SYNTAX_ERROR |
50 | The ixml grammar cannot be parsed. |
XMQ_ERROR_XSLT_COMPILE |
60 | The xslt stylesheet cannot be compiled. |
XMQ_ERROR_XSLT_TRANSFORM |
61 | The xslt transformation failed. |
XMQ_ERROR_XSD_COMPILE |
62 | The xsd schema cannot be compiled. |
XMQ_ERROR_XSD_INVALID |
63 | The document is not valid according to the xsd schema. |
XMQ_ERROR_EXCLUDED_FROM_BUILD |
64 | The feature was excluded when libxmq was built (eg XMQ_NO_JSON). |
XMQ_WARNING_QUOTES_NEEDED |
1000 | Warning, when parse succeeds, but it seems there is a mistake. |
XMQCoreTypeWhen loading xmq/xml/json as a config file, the content is parsed and decoded according the the requested type.
typedef enum { … } XMQCoreType;
Values
XMQ_CORE_BOOL |
||
XMQ_CORE_I8 |
Signed 8 bit integer. Can be decimal, hex (0x) or octal (0). | |
XMQ_CORE_I16 |
Signed 16 bit integer. Can be decimal, hex (0x) or octal (0). | |
XMQ_CORE_I32 |
Signed 32 bit integer. Can be decimal, hex (0x) or octal (0). | |
XMQ_CORE_I64 |
Signed 64 bit integer. Can be decimal, hex (0x) or octal (0). | |
XMQ_CORE_I128 |
Signed 128 bit integer. Can be decimal, hex (0x) or octal (0). | |
XMQ_CORE_U8 |
Unsigned 8 bit integer. Can be decimal, hex (0x) or octal (0). | |
XMQ_CORE_U16 |
Unsigned 16 bit integer. Can be decimal, hex (0x) or octal (0). | |
XMQ_CORE_U32 |
Unsigned 32 bit integer. Can be decimal, hex (0x) or octal (0). | |
XMQ_CORE_U64 |
Unsigned 64 bit integer. Can be decimal, hex (0x) or octal (0). | |
XMQ_CORE_U128 |
Unsigned 128 bit integer. Can be decimal, hex (0x) or octal (0). | |
XMQ_CORE_F32 |
Floating point 32bit. | |
XMQ_CORE_F64 |
Floating point 64bit. | |
XMQ_CORE_STRING |
Zero to infinite sized unicode string. No zero bytes. | |
XMQ_CORE_EMAIL |
String formatted as a valid email address. | |
XMQ_CORE_URI |
String formatted as a valid uri/iri. | |
XMQ_CORE_URL |
String formatted as a valid url. | |
XMQ_CORE_IP_ADDRESS |
Either a v4 or a v6. | |
XMQ_CORE_IPV4_ADDRESS |
128.0.0.1 | |
XMQ_CORE_IPV6_ADDRESS |
::0 | |
XMQ_BINARY_BASE64 |
Base64 encoded binary data. |
XMQNodeTypeThe kind of a node, see xmqGetNodeType.
typedef enum { … } XMQNodeType;
Values
XMQ_NODE_UNKNOWN |
0 | |
XMQ_NODE_ELEMENT |
1 | |
XMQ_NODE_TEXT |
3 | |
XMQ_NODE_CDATA |
4 | |
XMQ_NODE_ENTITY_REF |
5 | An entity reference that has not been expanded. The name is the entity name, a character reference has a name starting with #, e.g. #10 |
XMQ_NODE_PI |
7 | A processing instruction, the name is the target and the content the data. |
XMQ_NODE_COMMENT |
8 | |
XMQ_NODE_DOCUMENT |
9 | The document node, the parent of the root element and of the other top level nodes. |
XMQ_NODE_DOCTYPE |
14 | The doctype, the name is the doctype name. |
Defines
XMQ_ATTRSCreate an XMQAttrList from name value pairs, for xmqAddElementWithAttrs and xmqAddKeyValueWithAttrs, eg XMQ_ATTRS( { "id", "123" }, { "class", "info" } ).
#define XMQ_ATTRS(...) ((XMQAttrList) { (XMQAddAttr[]) { __VA_ARGS__ }, sizeof((XMQAddAttr[]) { __VA_ARGS__ }) / sizeof(XMQAddAttr) })