Group PJ_TINY_XML

group PJ_TINY_XML

Functions

pj_xml_node *pj_xml_parse(pj_pool_t *pool, char *msg, pj_size_t len)

Parse XML message into XML document with a single root node. The parser is capable of parsing XML processing instruction construct (“<?”) and XML comments (“<!–“), however such constructs will be ignored and will not be included in the resulted XML node tree.

Note that the XML message input buffer MUST be NULL terminated and have length at least len+1 (len MUST NOT include the NULL terminator).

Parameters:
  • pool – Pool to allocate memory from.

  • msg – The XML message to parse, MUST be NULL terminated.

  • len – The length of the message, not including NULL terminator.

Returns:

XML root node, or NULL if the XML document can not be parsed.

int pj_xml_print(const pj_xml_node *node, char *buf, pj_size_t len, pj_bool_t prolog)

Print XML into XML message. Note that the function WILL NOT NULL terminate the output.

Parameters:
  • node – The XML node to print.

  • buf – Buffer to hold the output message.

  • len – The length of the buffer.

  • prolog – If set to nonzero, will print XML prolog (“<?xml..”)

Returns:

The size of the printed message, or -1 if there is not sufficient space in the buffer to print the message.

pj_xml_node *pj_xml_clone(pj_pool_t *pool, const pj_xml_node *rhs)

Clone XML node and all subnodes.

Parameters:
  • pool – Pool to allocate memory for new nodes.

  • rhs – The node to clone.

Returns:

Cloned XML node, or NULL on fail.

pj_xml_node *pj_xml_node_new(pj_pool_t *pool, const pj_str_t *name)

Create an empty node.

Parameters:
  • pool – Pool.

  • name – Node name.

Returns:

The new node.

pj_xml_attr *pj_xml_attr_new(pj_pool_t *pool, const pj_str_t *name, const pj_str_t *value)

Create new XML attribute.

Parameters:
  • pool – Pool.

  • name – Attribute name.

  • value – Attribute value.

Returns:

The new XML attribute.

void pj_xml_add_node(pj_xml_node *parent, pj_xml_node *node)

Add node to another node.

Parameters:
  • parent – Parent node.

  • node – Node to be added to parent.

void pj_xml_add_attr(pj_xml_node *node, pj_xml_attr *attr)

Add attribute to a node.

Parameters:
  • node – Node.

  • attr – Attribute to add to node.

pj_xml_node *pj_xml_find_node(const pj_xml_node *parent, const pj_str_t *name)

Find first direct child node with the specified name.

Parameters:
  • parent – Parent node.

  • name – Node name to find.

Returns:

XML node found or NULL.

pj_xml_node *pj_xml_find_next_node(const pj_xml_node *parent, const pj_xml_node *node, const pj_str_t *name)

Find next direct child node with the specified name.

Parameters:
  • parent – Parent node.

  • node – node->next is the starting point.

  • name – Node name to find.

Returns:

XML node found or NULL.

pj_xml_node *pj_xml_find_node_rec(const pj_xml_node *parent, const pj_str_t *name)

Recursively find the first node with the specified name in the child nodes and their children.

Parameters:
  • parent – Parent node.

  • name – Node name to find.

Returns:

XML node found or NULL.

pj_xml_attr *pj_xml_find_attr(const pj_xml_node *node, const pj_str_t *name, const pj_str_t *value)

Find first attribute within a node with the specified name and optional value.

Parameters:
  • node – XML Node.

  • name – Attribute name to find.

  • value – Optional value to match.

Returns:

XML attribute found, or NULL.

pj_xml_node *pj_xml_find(const pj_xml_node *parent, const pj_str_t *name, const void *data, pj_bool_t (*match)(const pj_xml_node*, const void*))

Find a direct child node with the specified name and match the function.

Parameters:
  • parent – Parent node.

  • name – Optional name. If this is NULL, the name will not be matched.

  • data – Data to be passed to matching function.

  • match – Optional matching function.

Returns:

The first matched node, or NULL.

pj_xml_node *pj_xml_find_rec(const pj_xml_node *parent, const pj_str_t *name, const void *data, pj_bool_t (*match)(const pj_xml_node*, const void*))

Recursively find a child node with the specified name and match the function.

Parameters:
  • parent – Parent node.

  • name – Optional name. If this is NULL, the name will not be matched.

  • data – Data to be passed to matching function.

  • match – Optional matching function.

Returns:

The first matched node, or NULL.

struct pj_xml_attr
#include <xml.h>

This structure declares XML attribute.

Typedef for XML attribute.

Public Functions

PJ_DECL_LIST_MEMBER(pj_xml_attr)

Standard list elements.

Public Members

pj_str_t name

Attribute name.

pj_str_t value

Attribute value.

struct pj_xml_node_head
#include <xml.h>

This structure describes XML node head inside XML node structure.

Public Functions

PJ_DECL_LIST_MEMBER(pj_xml_node)

Standard list elements.

struct pj_xml_node
#include <xml.h>

This structure describes XML node.

Typedef for XML nodes.

Public Functions

PJ_DECL_LIST_MEMBER(pj_xml_node)

List prev and next member

Public Members

pj_str_t name

Node name.

pj_xml_attr attr_head

Attribute list.

pj_xml_node_head node_head

Node list.

pj_str_t content

Node content.