Contents

Enumerations


mxml_type_e

The XML node type.

Values

NameDescription
MXML_ELEMENTXML element with attributes
MXML_INTEGERInteger value
MXML_OPAQUEOpaque string
MXML_REALReal value
MXML_TEXTText fragment

Functions


mxmlAdd()

Add a node to a tree. Adds the specified node to the parent. If the child argument is not NULL, puts the new node before or after the specified child depending on the value of the where argument. If the child argument is NULL, puts the new node at the beginning of the child list (MXML_ADD_BEFORE) or at the end of the child list (MXML_ADD_AFTER). The constant MXML_ADD_TO_PARENT can be used to specify a NULL child pointer.

Syntax

void
mxmlAdd(
    mxml_node_t * parent,
    int where,
    mxml_node_t * child,
    mxml_node_t * node);

Arguments

NameDescription
parentParent node
whereWhere to add, MXML_ADD_BEFORE or MXML_ADD_AFTER
childChild node for where or MXML_ADD_TO_PARENT
nodeNode to add

Returns

Nothing.


mxmlDelete()

Delete a node and all of its children. If the specified node has a parent, this function first removes the node from its parent using the mxmlRemove() function.

Syntax

void
mxmlDelete(
    mxml_node_t * node);

Arguments

NameDescription
nodeNode to delete

Returns

Nothing.


mxmlElementGetAttr()

Get an attribute. This function returns NULL if the node is not an element or the named attribute does not exist.

Syntax

const char *
mxmlElementGetAttr(
    mxml_node_t * node,
    const char * name);

Arguments

NameDescription
nodeElement node
nameName of attribute

Returns

Attribute value or NULL


mxmlElementSetAttr()

Set an attribute. If the named attribute already exists, the value of the attribute is replaced by the new string value. The string value is copied into the element node. This function does nothing if the node is not an element.

Syntax

void
mxmlElementSetAttr(
    mxml_node_t * node,
    const char * name,
    const char * value);

Arguments

NameDescription
nodeElement node
nameName of attribute
valueAttribute value

Returns

Nothing.


mxmlFindElement()

Find the named element. The search is constrained by the name, attribute name, and value; any NULL names or values are treated as wildcards, so different kinds of searches can be implemented by looking for all elements of a given name or all elements with a specific attribute. The descend argument determines whether the search descends into child nodes; normally you will use MXML_DESCEND_FIRST for the initial search and MXML_NO_DESCEND to find additional direct descendents of the node. The top node argument constrains the search to a particular node's children.

Syntax

mxml_node_t *
mxmlFindElement(
    mxml_node_t * node,
    mxml_node_t * top,
    const char * name,
    const char * attr,
    const char * value,
    int descend);

Arguments

NameDescription
nodeCurrent node
topTop node
nameElement name or NULL for any
attrAttribute name, or NULL for none
valueAttribute value, or NULL for any
descendDescend into tree - MXML_DESCEND, MXML_NO_DESCEND, or MXML_DESCEND_FIRST

Returns

Element node or NULL


mxmlLoadFile()

Load a file into an XML node tree. The nodes in the specified file are added to the specified top node. If no top node is provided, the XML file MUST be well-formed with a single parent node like <?xml> for the entire file. The callback function returns the value type that should be used for child nodes. If MXML_NO_CALLBACK is specified then all child nodes will be either MXML_ELEMENT or MXML_TEXT nodes.

Syntax

mxml_node_t *
mxmlLoadFile(
    mxml_node_t * top,
    FILE * fp,
    mxml_type_t (*cb)(mxml_node_t *));

Arguments

NameDescription
topTop node
fpFile to read from
(*cb)(mxml_node_t *)Callback function or MXML_NO_CALLBACK

Returns

First node or NULL if the file could not be read.


mxmlLoadString()

Load a string into an XML node tree. The nodes in the specified string are added to the specified top node. If no top node is provided, the XML string MUST be well-formed with a single parent node like <?xml> for the entire string. The callback function returns the value type that should be used for child nodes. If MXML_NO_CALLBACK is specified then all child nodes will be either MXML_ELEMENT or MXML_TEXT nodes.

Syntax

mxml_node_t *
mxmlLoadString(
    mxml_node_t * top,
    const char * s,
    mxml_type_t (*cb)(mxml_node_t *));

Arguments

NameDescription
topTop node
sString to load
(*cb)(mxml_node_t *)Callback function or MXML_NO_CALLBACK

Returns

First node or NULL if the string has errors.


mxmlNewElement()

Create a new element node. The new element node is added to the end of the specified parent's child list. The constant MXML_NO_PARENT can be used to specify that the new element node has no parent.

Syntax

mxml_node_t *
mxmlNewElement(
    mxml_node_t * parent,
    const char * name);

Arguments

NameDescription
parentParent node or MXML_NO_PARENT
nameName of element

Returns

New node


mxmlNewInteger()

Create a new integer node. The new integer node is added to the end of the specified parent's child list. The constant MXML_NO_PARENT can be used to specify that the new integer node has no parent.

Syntax

mxml_node_t *
mxmlNewInteger(
    mxml_node_t * parent,
    int integer);

Arguments

NameDescription
parentParent node or MXML_NO_PARENT
integerInteger value

Returns

New node


mxmlNewOpaque()

Create a new opaque string. The new opaque node is added to the end of the specified parent's child list. The constant MXML_NO_PARENT can be used to specify that the new opaque node has no parent. The opaque string must be nul-terminated and is copied into the new node.

Syntax

mxml_node_t *
mxmlNewOpaque(
    mxml_node_t * parent,
    const char * opaque);

Arguments

NameDescription
parentParent node or MXML_NO_PARENT
opaqueOpaque string

Returns

New node


mxmlNewReal()

Create a new real number node. The new real number node is added to the end of the specified parent's child list. The constant MXML_NO_PARENT can be used to specify that the new real number node has no parent.

Syntax

mxml_node_t *
mxmlNewReal(
    mxml_node_t * parent,
    double real);

Arguments

NameDescription
parentParent node or MXML_NO_PARENT
realReal number value

Returns

New node


mxmlNewText()

Create a new text fragment node. The new text node is added to the end of the specified parent's child list. The constant MXML_NO_PARENT can be used to specify that the new text node has no parent. The whitespace parameter is used to specify whether leading whitespace is present before the node. The text string must be nul-terminated and is copied into the new node.

Syntax

mxml_node_t *
mxmlNewText(
    mxml_node_t * parent,
    int whitespace,
    const char * string);

Arguments

NameDescription
parentParent node or MXML_NO_PARENT
whitespace1 = leading whitespace, 0 = no whitespace
stringString

Returns

New node


mxmlRemove()

Remove a node from its parent. Does not free memory used by the node - use mxmlDelete() for that. This function does nothing if the node has no parent.

Syntax

void
mxmlRemove(
    mxml_node_t * node);

Arguments

NameDescription
nodeNode to remove

Returns

Nothing.


mxmlSaveFile()

Save an XML tree to a file. The callback argument specifies a function that returns a whitespace character or nul (0) before and after each element. If MXML_NO_CALLBACK is specified, whitespace will only be added before MXML_TEXT nodes with leading whitespace and before attribute names inside opening element tags.

Syntax

int
mxmlSaveFile(
    mxml_node_t * node,
    FILE * fp,
    int (*cb)(mxml_node_t *int));

Arguments

NameDescription
nodeNode to write
fpFile to write to
(*cb)(mxml_node_t *int)Whitespace callback or MXML_NO_CALLBACK

Returns

0 on success, -1 on error.


mxmlSaveString()

Save an XML node tree to a string. This function returns the total number of bytes that would be required for the string but only copies (bufsize - 1) characters into the specified buffer.

Syntax

int
mxmlSaveString(
    mxml_node_t * node,
    char * buffer,
    int bufsize,
    int (*cb)(mxml_node_t *int));

Arguments

NameDescription
nodeNode to write
bufferString buffer
bufsizeSize of string buffer
(*cb)(mxml_node_t *int)Whitespace callback or MXML_NO_CALLBACK

Returns

Size of string


mxmlWalkNext()

Walk to the next logical node in the tree. The descend argument controls whether the first child is considered to be the next node. The top node argument constrains the walk to the node's children.

Syntax

mxml_node_t *
mxmlWalkNext(
    mxml_node_t * node,
    mxml_node_t * top,
    int descend);

Arguments

NameDescription
nodeCurrent node
topTop node
descendDescend into tree - MXML_DESCEND, MXML_NO_DESCEND, or MXML_DESCEND_FIRST

Returns

Next node or NULL


mxmlWalkPrev()

Walk to the previous logical node in the tree. The descend argument controls whether the previous node's last child is considered to be the previous node. The top node argument constrains the walk to the node's children.

Syntax

mxml_node_t *
mxmlWalkPrev(
    mxml_node_t * node,
    mxml_node_t * top,
    int descend);

Arguments

NameDescription
nodeCurrent node
topTop node
descendDescend into tree - MXML_DESCEND, MXML_NO_DESCEND, or MXML_DESCEND_FIRST

Returns

Previous node or NULL


mxml_strdup()

Duplicate a string.

Syntax

char *
mxml_strdup(
    const char * s);

Arguments

NameDescription
sString to duplicate

Returns

New string pointer

Structures


mxml_attr_s

An XML element attribute value.

Definition

struct mxml_attr_s
{
  char * name;
  char * value;
};

Members

NameDescription
nameAttribute name
valueAttribute value


mxml_node_s

Data types...

Definition

struct mxml_node_s
{
  mxml_node_t * child;
  mxml_node_t * last_child;
  mxml_node_t * next;
  mxml_node_t * parent;
  mxml_node_t * prev;
  mxml_type_t type;
  mxml_value_t value;
};

Members

NameDescription
childFirst child node
last_childLast child node
nextNext node under same parent
parentParent node
prevPrevious node under same parent
typeNode type
valueNode value


mxml_text_s

An XML text value.

Definition

struct mxml_text_s
{
  char * string;
  int whitespace;
};

Members

NameDescription
stringFragment string
whitespaceLeading whitespace?


mxml_value_s

An XML element value.

Definition

struct mxml_value_s
{
  mxml_attr_t * attrs;
  char * name;
  int num_attrs;
};

Members

NameDescription
attrsAttributes
nameName of element
num_attrsNumber of attributes

Types


mxml_attr_t

An XML element attribute value.

Definition

typedef struct mxml_attr_s mxml_attr_t;

mxml_element_t

An XML element value.

Definition

typedef struct mxml_value_s mxml_element_t;

mxml_node_t

An XML node.

Definition

typedef struct mxml_node_s mxml_node_t;

mxml_text_t

An XML text value.

Definition

typedef struct mxml_text_s mxml_text_t;

mxml_type_t

The XML node type.

Definition

typedef enum mxml_type_e mxml_type_t;

mxml_value_t

An XML node value.

Definition

typedef union mxml_value_u mxml_value_t;

Unions


mxml_value_u

An XML node value.

Definition

struct mxml_value_u
{
  mxml_element_t element;
  int integer;
  char * opaque;
  double real;
  mxml_text_t text;
};

Members

NameDescription
elementElement
integerInteger number
opaqueOpaque string
realReal number
textText fragment