BLOG | DOCUMENTATION | TRAC

Home --> Documentations --> PJLIB-UTIL Reference

Mini/Tiny XML Parser/Helper

Data Structures

struct  pj_xml_attr
 
struct  pj_xml_node_head
 
struct  pj_xml_node
 

Functions

pj_xml_nodepj_xml_parse (pj_pool_t *pool, char *msg, pj_size_t len)
 
int pj_xml_print (const pj_xml_node *node, char *buf, pj_size_t len, pj_bool_t prolog)
 
pj_xml_nodepj_xml_clone (pj_pool_t *pool, const pj_xml_node *rhs)
 
pj_xml_nodepj_xml_node_new (pj_pool_t *pool, const pj_str_t *name)
 
pj_xml_attrpj_xml_attr_new (pj_pool_t *pool, const pj_str_t *name, const pj_str_t *value)
 
void pj_xml_add_node (pj_xml_node *parent, pj_xml_node *node)
 
void pj_xml_add_attr (pj_xml_node *node, pj_xml_attr *attr)
 
pj_xml_nodepj_xml_find_node (const pj_xml_node *parent, const pj_str_t *name)
 
pj_xml_nodepj_xml_find_next_node (const pj_xml_node *parent, const pj_xml_node *node, const pj_str_t *name)
 
pj_xml_nodepj_xml_find_node_rec (const pj_xml_node *parent, const pj_str_t *name)
 
pj_xml_attrpj_xml_find_attr (const pj_xml_node *node, const pj_str_t *name, const pj_str_t *value)
 
pj_xml_nodepj_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 *))
 
pj_xml_nodepj_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 *))
 

Detailed Description

Function Documentation

void pj_xml_add_attr ( pj_xml_node node,
pj_xml_attr attr 
)

Add attribute to a node.

Parameters
nodeNode.
attrAttribute to add to node.
void pj_xml_add_node ( pj_xml_node parent,
pj_xml_node node 
)

Add node to another node.

Parameters
parentParent node.
nodeNode to be added to parent.
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
poolPool.
nameAttribute name.
valueAttribute value.
Returns
The new XML attribute.
pj_xml_node* pj_xml_clone ( pj_pool_t pool,
const pj_xml_node rhs 
)

Clone XML node and all subnodes.

Parameters
poolPool to allocate memory for new nodes.
rhsThe node to clone.
Returns
Cloned XML node, or NULL on fail.
pj_xml_node* pj_xml_find ( const pj_xml_node parent,
const pj_str_t name,
const void *  data,
pj_bool_t(*)(const pj_xml_node *, const void *)  match 
)

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

Parameters
parentParent node.
nameOptional name. If this is NULL, the name will not be matched.
dataData to be passed to matching function.
matchOptional matching function.
Returns
The first matched node, 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
nodeXML Node.
nameAttribute name to find.
valueOptional value to match.
Returns
XML attribute 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
parentParent node.
nodenode->next is the starting point.
nameNode name to find.
Returns
XML node found or NULL.
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
parentParent node.
nameNode 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
parentParent node.
nameNode name to find.
Returns
XML node found 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(*)(const pj_xml_node *, const void *)  match 
)

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

Parameters
parentParent node.
nameOptional name. If this is NULL, the name will not be matched.
dataData to be passed to matching function.
matchOptional matching function.
Returns
The first matched node, or NULL.
pj_xml_node* pj_xml_node_new ( pj_pool_t pool,
const pj_str_t name 
)

Create an empty node.

Parameters
poolPool.
nameNode name.
Returns
The new node.
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.

Parameters
poolPool to allocate memory from.
msgThe XML message to parse.
lenThe length of the message.
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
nodeThe XML node to print.
bufBuffer to hold the output message.
lenThe length of the buffer.
prologIf 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.

 


PJLIB-UTIL Open Source, small footprint, and portable asynchronous/caching DNS resolver, text scanner, STUN client, and XML library
Copyright (C) 2006-2009 Teluu Inc.