gwenhywfar  5.11.1beta
xml.h File Reference
#include <gwenhywfar/gwenhywfarapi.h>
#include <gwenhywfar/stringlist.h>
#include <gwenhywfar/types.h>
#include <gwenhywfar/list2.h>
#include <gwenhywfar/syncio.h>
#include <stdio.h>
#include <gwenhywfar/xmlctx.h>
#include <gwenhywfar/fastbuffer.h>
#include <gwenhywfar/db.h>

Go to the source code of this file.

Macros

Read Flags
#define GWEN_XML_FLAGS_DEFAULT
 
#define GWEN_XML_FLAGS_HANDLE_COMMENTS   0x0001
 
#define GWEN_XML_FLAGS_HANDLE_HEADERS   0x0080
 
#define GWEN_XML_FLAGS_HANDLE_NAMESPACES   0x0200
 
#define GWEN_XML_FLAGS_HANDLE_OPEN_HTMLTAGS   0x0004
 
#define GWEN_XML_FLAGS_INDENT   0x0002
 
#define GWEN_XML_FLAGS_KEEP_BLANKS   0x0020
 
#define GWEN_XML_FLAGS_KEEP_CNTRL   0x0010
 
#define GWEN_XML_FLAGS_NO_CONDENSE   0x0008
 
#define GWEN_XML_FLAGS_SGML   0x0400
 
#define GWEN_XML_FLAGS_SIMPLE   0x0040
 
#define GWEN_XML_FLAGS_TOLERANT_ENDTAGS   0x0100
 

Functions

Constructors and Destructors
GWENHYWFAR_API GWEN_XMLNODEGWEN_XMLNode_dup (const GWEN_XMLNODE *n)
 
GWENHYWFAR_API void GWEN_XMLNode_free (GWEN_XMLNODE *n)
 
GWENHYWFAR_API void GWEN_XMLNode_freeAll (GWEN_XMLNODE *n)
 
GWENHYWFAR_API GWEN_XMLNODEGWEN_XMLNode_new (GWEN_XMLNODE_TYPE t, const char *data)
 
Managing Headers

Headers are special tags in XML files which describe the document (such as <?xml?> or <!DOCTYPE>).

If the flag GWEN_XML_FLAGS_HANDLE_HEADERS is on upon reading of files these special toplevel tags are added to the current node's header list instead of the normal children node list.

If the same flag is given when writing files the header tags of the given root node are written to the output stream before its children.

Header nodes are identified as nodes whose name begins with '?' or '!'.

GWENHYWFAR_API void GWEN_XMLNode_AddHeader (GWEN_XMLNODE *root, GWEN_XMLNODE *nh)
 
GWENHYWFAR_API void GWEN_XMLNode_ClearHeaders (GWEN_XMLNODE *root)
 
GWENHYWFAR_API void GWEN_XMLNode_DelHeader (GWEN_XMLNODE *root, GWEN_XMLNODE *nh)
 
GWENHYWFAR_API GWEN_XMLNODEGWEN_XMLNode_GetHeader (const GWEN_XMLNODE *n)
 
Managing Properties/Attributes

A property (in XML notation this is called attribute) is given within a tag (in XML notation this is called element), like in this example:

<tag property="1" />
GWENHYWFAR_API void GWEN_XMLNode_CopyProperties (GWEN_XMLNODE *tn, const GWEN_XMLNODE *sn, int overwrite)
 
GWENHYWFAR_API int GWEN_XMLNode_ExpandProperties (const GWEN_XMLNODE *tn, GWEN_DB_NODE *dbVars)
 
GWENHYWFAR_API int GWEN_XMLNode_GetIntProperty (const GWEN_XMLNODE *n, const char *name, int defaultValue)
 
GWENHYWFAR_API const char * GWEN_XMLNode_GetProperty (const GWEN_XMLNODE *n, const char *name, const char *defaultValue)
 
GWENHYWFAR_API void GWEN_XMLNode_SetIntProperty (GWEN_XMLNODE *n, const char *name, int value)
 
GWENHYWFAR_API void GWEN_XMLNode_SetProperty (GWEN_XMLNODE *n, const char *name, const char *value)
 
Type And Data
GWENHYWFAR_API const char * GWEN_XMLNode_GetData (const GWEN_XMLNODE *n)
 
GWENHYWFAR_API const char * GWEN_XMLNode_GetNamespace (const GWEN_XMLNODE *n)
 
GWENHYWFAR_API GWEN_XMLNODE_TYPE GWEN_XMLNode_GetType (const GWEN_XMLNODE *n)
 
GWENHYWFAR_API void GWEN_XMLNode_SetData (GWEN_XMLNODE *n, const char *data)
 
GWENHYWFAR_API void GWEN_XMLNode_SetNamespace (GWEN_XMLNODE *n, const char *s)
 
Usage Counter

The usage counter of a node is only used by applications, not by Gwenhywfar itself. So if the application does not set this counter it will always be zero.

An application could use this counter to check whether a given node is still in use by some parts of the application in order to free unused nodes.

GWENHYWFAR_API void GWEN_XMLNode_DecUsage (GWEN_XMLNODE *n)
 
GWENHYWFAR_API uint32_t GWEN_XMLNode_GetUsage (const GWEN_XMLNODE *n)
 
GWENHYWFAR_API void GWEN_XMLNode_IncUsage (GWEN_XMLNODE *n)
 
Iterating Through an XML Tree
GWENHYWFAR_API GWEN_XMLNODEGWEN_XMLNode_FindFirstTag (const GWEN_XMLNODE *n, const char *tname, const char *pname, const char *pvalue)
 
GWENHYWFAR_API GWEN_XMLNODEGWEN_XMLNode_FindNextTag (const GWEN_XMLNODE *n, const char *tname, const char *pname, const char *pvalue)
 
GWENHYWFAR_API GWEN_XMLNODEGWEN_XMLNode_GetChild (const GWEN_XMLNODE *n)
 
GWENHYWFAR_API GWEN_XMLNODEGWEN_XMLNode_GetFirstData (const GWEN_XMLNODE *n)
 
GWENHYWFAR_API GWEN_XMLNODEGWEN_XMLNode_GetFirstTag (const GWEN_XMLNODE *n)
 
GWENHYWFAR_API GWEN_XMLNODEGWEN_XMLNode_GetNextData (const GWEN_XMLNODE *n)
 
GWENHYWFAR_API GWEN_XMLNODEGWEN_XMLNode_GetNextTag (const GWEN_XMLNODE *n)
 
GWENHYWFAR_API GWEN_XMLNODEGWEN_XMLNode_GetNodeByXPath (GWEN_XMLNODE *n, const char *path, uint32_t flags)
 
GWENHYWFAR_API GWEN_XMLNODEGWEN_XMLNode_GetParent (const GWEN_XMLNODE *n)
 
GWENHYWFAR_API int GWEN_XMLNode_GetXPath (const GWEN_XMLNODE *n1, const GWEN_XMLNODE *n2, GWEN_BUFFER *nbuf)
 
GWENHYWFAR_API int GWEN_XMLNode_IsChildOf (const GWEN_XMLNODE *parent, const GWEN_XMLNODE *child)
 
GWENHYWFAR_API GWEN_XMLNODEGWEN_XMLNode_Next (const GWEN_XMLNODE *n)
 
Managing Nodes
GWENHYWFAR_API void GWEN_XMLNode_AddChild (GWEN_XMLNODE *n, GWEN_XMLNODE *child)
 
GWENHYWFAR_API void GWEN_XMLNode_AddChildrenOnly (GWEN_XMLNODE *n, GWEN_XMLNODE *nn, int copythem)
 
GWENHYWFAR_API GWEN_XMLNODEGWEN_XMLNode_FindNode (const GWEN_XMLNODE *n, GWEN_XMLNODE_TYPE t, const char *data)
 
GWENHYWFAR_API void GWEN_XMLNode_RemoveChildren (GWEN_XMLNODE *n)
 
GWENHYWFAR_API void GWEN_XMLNode_UnlinkChild (GWEN_XMLNODE *n, GWEN_XMLNODE *child)
 
Reading And Writing From/To Streams
GWENHYWFAR_API int GWEN_XML_ReadFile (GWEN_XMLNODE *n, const char *filepath, uint32_t flags)
 
GWENHYWFAR_API int GWEN_XML_ReadFromFastBuffer (GWEN_XML_CONTEXT *ctx, GWEN_FAST_BUFFER *fb)
 
GWENHYWFAR_API int GWEN_XMLContext_ReadFromFile (GWEN_XML_CONTEXT *ctx, const char *fname)
 
GWENHYWFAR_API int GWEN_XMLContext_ReadFromIo (GWEN_XML_CONTEXT *ctx, GWEN_SYNCIO *io)
 
GWENHYWFAR_API int GWEN_XMLContext_ReadFromString (GWEN_XML_CONTEXT *ctx, const char *text)
 
GWENHYWFAR_API void GWEN_XMLNode_AddNameSpace (GWEN_XMLNODE *n, const GWEN_XMLNODE_NAMESPACE *ns)
 
GWENHYWFAR_API GWEN_XMLNODE_NAMESPACEGWEN_XMLNode_FindNameSpaceByName (const GWEN_XMLNODE *n, const char *s)
 
GWENHYWFAR_API GWEN_XMLNODE_NAMESPACEGWEN_XMLNode_FindNameSpaceByUrl (const GWEN_XMLNODE *n, const char *s)
 
GWENHYWFAR_API GWEN_XMLNODEGWEN_XMLNode_fromString (const char *s, int len, uint32_t flags)
 
GWENHYWFAR_API GWEN_XMLNODE_NAMESPACE_LISTGWEN_XMLNode_GetNameSpaces (const GWEN_XMLNODE *n)
 
GWENHYWFAR_API int GWEN_XMLNode_Globalize (GWEN_XMLNODE *n)
 
GWENHYWFAR_API int GWEN_XMLNode_GlobalizeWithList (GWEN_XMLNODE *n, GWEN_XMLNODE_NAMESPACE_LIST *l, uint32_t *pLastId)
 
GWENHYWFAR_API int GWEN_XMLNode_NormalizeNameSpaces (GWEN_XMLNODE *n)
 
GWENHYWFAR_API int GWEN_XMLNode_StripNamespaces (GWEN_XMLNODE *n)
 
GWENHYWFAR_API int GWEN_XMLNode_toBuffer (const GWEN_XMLNODE *n, GWEN_BUFFER *buf, uint32_t flags)
 
GWENHYWFAR_API int GWEN_XMLNode_WriteFile (const GWEN_XMLNODE *n, const char *fname, uint32_t flags)
 
GWENHYWFAR_API int GWEN_XMLNode_WriteToStream (const GWEN_XMLNODE *n, GWEN_XML_CONTEXT *ctx, GWEN_SYNCIO *sio)
 
Handling Tags As Variables

These functions are only kept for compatibility reasons. You should use functions like GWEN_XMLNode_GetCharValueByPath() instead.

These functions look for a tag, read their first data element and return it as if it was a DB variable. This simplifies access to simple tags containing simple data tags only. E.g. if your XML structure is this:

<test>
<X> 15 </X>
<Y> 10 </Y>
</test>

... then you can access the value of X with the following call:

x=GWEN_XMLNode_GetIntValue(testNode, "X", 0);
GWENHYWFAR_API int GWEN_XMLNode_GetIntValue(const GWEN_XMLNODE *n, const char *name, int defValue)

If the given variables do not exist or have no value then the also given default value will be returned.

GWENHYWFAR_API const char * GWEN_XMLNode_GetCharValue (const GWEN_XMLNODE *n, const char *name, const char *defValue)
 
GWENHYWFAR_API int GWEN_XMLNode_GetIntValue (const GWEN_XMLNODE *n, const char *name, int defValue)
 
GWENHYWFAR_API const char * GWEN_XMLNode_GetLocalizedCharValue (const GWEN_XMLNODE *n, const char *name, const char *defValue)
 
GWENHYWFAR_API void GWEN_XMLNode_SetCharValue (GWEN_XMLNODE *n, const char *name, const char *value)
 
GWENHYWFAR_API void GWEN_XMLNode_SetIntValue (GWEN_XMLNODE *n, const char *name, int value)
 
Handling Tags As Variables Using Paths

These functions look for a tag, read their first data element and return it as if it was a DB variable. This simplifies access to simple tags containing simple data tags only. E.g. if your XML structure is this:

<test>
<X> 15 </X>
<Y> 10 </Y>
</test>

... then you can access the value of X with the following call:

x=GWEN_XMLNode_GetIntValue(testNode, "X", 0);

If the given variables do not exist or have no value then the also given default value will be returned.

In addition to functions like GWEN_XMLNode_SetCharValue you can use full paths here.

GWENHYWFAR_API const char * GWEN_XMLNode_GetCharValueByPath (GWEN_XMLNODE *n, const char *path, const char *defValue)
 
GWENHYWFAR_API int GWEN_XMLNode_GetIntValueByPath (GWEN_XMLNODE *n, const char *name, int defValue)
 
GWENHYWFAR_API int GWEN_XMLNode_SetCharValueByPath (GWEN_XMLNODE *n, uint32_t flags, const char *name, const char *value)
 
GWENHYWFAR_API int GWEN_XMLNode_SetIntValueByPath (GWEN_XMLNODE *n, uint32_t flags, const char *name, int value)
 

Path flags for GWEN_XMLNode_SetCharValueByPath etc

#define GWEN_XML_PATH_FLAGS_OVERWRITE_VALUES   0x00010000
 
typedef struct GWEN__XMLNODE GWEN_XMLNODE
 
typedef struct GWEN_XMLNODE_NAMESPACE GWEN_XMLNODE_NAMESPACE
 
enum  GWEN_XMLNODE_TYPE { GWEN_XMLNodeTypeTag =0 , GWEN_XMLNodeTypeData , GWEN_XMLNodeTypeComment }
 

Debugging

GWENHYWFAR_API void GWEN_XMLNode_Dump (const GWEN_XMLNODE *n, int ind)
 
GWENHYWFAR_API GWEN_XMLNODE_NAMESPACEGWEN_XMLNode_NameSpace_dup (const GWEN_XMLNODE_NAMESPACE *ns)
 
GWENHYWFAR_API void GWEN_XMLNode_NameSpace_free (GWEN_XMLNODE_NAMESPACE *ns)
 
GWENHYWFAR_API const char * GWEN_XMLNode_NameSpace_GetName (const GWEN_XMLNODE_NAMESPACE *ns)
 
GWENHYWFAR_API const char * GWEN_XMLNode_NameSpace_GetUrl (const GWEN_XMLNODE_NAMESPACE *ns)
 
GWENHYWFAR_API GWEN_XMLNODE_NAMESPACEGWEN_XMLNode_NameSpace_new (const char *name, const char *url)
 
typedef struct GWEN_XMLNODE_PATH GWEN_XMLNODE_PATH
 
GWENHYWFAR_API int GWEN_XMLNode_Path_Dive (GWEN_XMLNODE_PATH *np, GWEN_XMLNODE *n)
 
GWENHYWFAR_API void GWEN_XMLNode_Path_Dump (GWEN_XMLNODE_PATH *np)
 
GWENHYWFAR_API GWEN_XMLNODE_PATHGWEN_XMLNode_Path_dup (const GWEN_XMLNODE_PATH *np)
 
GWENHYWFAR_API void GWEN_XMLNode_Path_free (GWEN_XMLNODE_PATH *np)
 
GWENHYWFAR_API GWEN_XMLNODE_PATHGWEN_XMLNode_Path_new (void)
 
GWENHYWFAR_API GWEN_XMLNODEGWEN_XMLNode_Path_Surface (GWEN_XMLNODE_PATH *np)
 

Macro Definition Documentation

◆ GWEN_XML_FLAGS_DEFAULT

#define GWEN_XML_FLAGS_DEFAULT
Value:
(\
GWEN_XML_FLAGS_INDENT | \
GWEN_XML_FLAGS_HANDLE_COMMENTS | \
GWEN_XML_FLAGS_HANDLE_HEADERS\
)

combination of other flags resembling the default flags

Definition at line 117 of file xml.h.

◆ GWEN_XML_FLAGS_HANDLE_COMMENTS

#define GWEN_XML_FLAGS_HANDLE_COMMENTS   0x0001

if set then comments are read. Otherwise they are ignored when reading a file

Definition at line 60 of file xml.h.

◆ GWEN_XML_FLAGS_HANDLE_HEADERS

#define GWEN_XML_FLAGS_HANDLE_HEADERS   0x0080

apply special treatment to toplevel header tags (such as <?xml>)

Definition at line 94 of file xml.h.

◆ GWEN_XML_FLAGS_HANDLE_NAMESPACES

#define GWEN_XML_FLAGS_HANDLE_NAMESPACES   0x0200

Definition at line 105 of file xml.h.

◆ GWEN_XML_FLAGS_HANDLE_OPEN_HTMLTAGS

#define GWEN_XML_FLAGS_HANDLE_OPEN_HTMLTAGS   0x0004

Let the parser accept some HTML which are known to be unclosed (e.g. the tag "BR" in HTML tags is never closed). If not set a "BR" tag without a corresponding "/BR" will produce an error.

Definition at line 73 of file xml.h.

◆ GWEN_XML_FLAGS_INDENT

#define GWEN_XML_FLAGS_INDENT   0x0002

Indent lines according to node level when writing nodes. This increases the readability of the resulting file.

Definition at line 66 of file xml.h.

◆ GWEN_XML_FLAGS_KEEP_BLANKS

#define GWEN_XML_FLAGS_KEEP_BLANKS   0x0020

Definition at line 87 of file xml.h.

◆ GWEN_XML_FLAGS_KEEP_CNTRL

#define GWEN_XML_FLAGS_KEEP_CNTRL   0x0010

If set then control characters (such as CR, LF) will not be removed from data.

Definition at line 85 of file xml.h.

◆ GWEN_XML_FLAGS_NO_CONDENSE

#define GWEN_XML_FLAGS_NO_CONDENSE   0x0008

If set then data will not be condensed (e.g. multiple spaces will not be replaced by a single one).

Definition at line 79 of file xml.h.

◆ GWEN_XML_FLAGS_SGML

#define GWEN_XML_FLAGS_SGML   0x0400

Handle input as kind of SGML data. This means that elements with text data are handled as if they had a closing element (e.g. "<DESC>Text" is handles like "<DESC>Text</DESC>").

Definition at line 112 of file xml.h.

◆ GWEN_XML_FLAGS_SIMPLE

#define GWEN_XML_FLAGS_SIMPLE   0x0040

Definition at line 89 of file xml.h.

◆ GWEN_XML_FLAGS_TOLERANT_ENDTAGS

#define GWEN_XML_FLAGS_TOLERANT_ENDTAGS   0x0100

If this flag is given this module will be more tolerant when encountering and end element (e.g. </html>). If the name of the end element does not match the currently open element then the element to be closed is searched above the currently open element. This works around problems with malformed XML files.

Definition at line 103 of file xml.h.

◆ GWEN_XML_PATH_FLAGS_OVERWRITE_VALUES

#define GWEN_XML_PATH_FLAGS_OVERWRITE_VALUES   0x00010000

Definition at line 133 of file xml.h.

Typedef Documentation

◆ GWEN_XMLNODE

typedef struct GWEN__XMLNODE GWEN_XMLNODE

The abstract type XMLNODE. Each node is one node in the document tree and can represent different things, see GWEN_XMLNODE_TYPE.

Definition at line 1 of file xml.h.

◆ GWEN_XMLNODE_NAMESPACE

Definition at line 1 of file xml.h.

◆ GWEN_XMLNODE_PATH

Definition at line 852 of file xml.h.

Enumeration Type Documentation

◆ GWEN_XMLNODE_TYPE

The possible types of a GWEN_XMLNODE.

Enumerator
GWEN_XMLNodeTypeTag 

A node can be a tag (in XML notation these are called elements).

GWEN_XMLNodeTypeData 

A node can be some data.

GWEN_XMLNodeTypeComment 

A node can be some XML comment.

Definition at line 142 of file xml.h.

Function Documentation

◆ GWEN_XML_ReadFile()

GWENHYWFAR_API int GWEN_XML_ReadFile ( GWEN_XMLNODE n,
const char *  filepath,
uint32_t  flags 
)

Reads all tags/elements from a file and adds them as children to the given node.

◆ GWEN_XML_ReadFromFastBuffer()

GWENHYWFAR_API int GWEN_XML_ReadFromFastBuffer ( GWEN_XML_CONTEXT ctx,
GWEN_FAST_BUFFER fb 
)

◆ GWEN_XMLContext_ReadFromFile()

GWENHYWFAR_API int GWEN_XMLContext_ReadFromFile ( GWEN_XML_CONTEXT ctx,
const char *  fname 
)

◆ GWEN_XMLContext_ReadFromIo()

GWENHYWFAR_API int GWEN_XMLContext_ReadFromIo ( GWEN_XML_CONTEXT ctx,
GWEN_SYNCIO io 
)

Reads a single element (and all its sub-elements) from an IO layer.

◆ GWEN_XMLContext_ReadFromString()

GWENHYWFAR_API int GWEN_XMLContext_ReadFromString ( GWEN_XML_CONTEXT ctx,
const char *  text 
)

◆ GWEN_XMLNode_AddChild()

GWENHYWFAR_API void GWEN_XMLNode_AddChild ( GWEN_XMLNODE n,
GWEN_XMLNODE child 
)

Adds a node as a child to another one. This function does not make deep copies. Instead it takes over ownership of the new child.

Parameters
nnode to which the new node is to be added (i.e. the node which becomes the parent of the second argument)
childchild which is to be added (this function takes over ownership of that node, so you MUST NOT free the node yourself)

◆ GWEN_XMLNode_AddChildrenOnly()

GWENHYWFAR_API void GWEN_XMLNode_AddChildrenOnly ( GWEN_XMLNODE n,
GWEN_XMLNODE nn,
int  copythem 
)

Adds the children of the second argument as new children to the first one.

Parameters
nnode which is to become parent of the second argument's children
nnnode whose children are to be moved.
copythemif 0 then the children will be moved (leaving the node of the second argument without children), otherwise deep copies will be made and the node from the second argument will not be altered. co

◆ GWEN_XMLNode_AddHeader()

GWENHYWFAR_API void GWEN_XMLNode_AddHeader ( GWEN_XMLNODE root,
GWEN_XMLNODE nh 
)

Adds a node as a header to the given root node.

◆ GWEN_XMLNode_AddNameSpace()

GWENHYWFAR_API void GWEN_XMLNode_AddNameSpace ( GWEN_XMLNODE n,
const GWEN_XMLNODE_NAMESPACE ns 
)

◆ GWEN_XMLNode_ClearHeaders()

GWENHYWFAR_API void GWEN_XMLNode_ClearHeaders ( GWEN_XMLNODE root)

Clears the given root nodes' list of headers. All the tags in the header list are also freed.

◆ GWEN_XMLNode_CopyProperties()

GWENHYWFAR_API void GWEN_XMLNode_CopyProperties ( GWEN_XMLNODE tn,
const GWEN_XMLNODE sn,
int  overwrite 
)

This function copies the properties/attributes of one tag/element to another one.

Parameters
tndestination node (must be a tag/element)
snsource node (must be a tag/element)
overwriteif !=0 then existing properties/attributes in the destination node will be overwritten.

◆ GWEN_XMLNode_DecUsage()

GWENHYWFAR_API void GWEN_XMLNode_DecUsage ( GWEN_XMLNODE n)

◆ GWEN_XMLNode_DelHeader()

GWENHYWFAR_API void GWEN_XMLNode_DelHeader ( GWEN_XMLNODE root,
GWEN_XMLNODE nh 
)

Removes a node from the given root nodes' header list. The header node is just removed from the list, not freed !

◆ GWEN_XMLNode_Dump()

GWENHYWFAR_API void GWEN_XMLNode_Dump ( const GWEN_XMLNODE n,
int  ind 
)

Dumps the content of the given XML node and all its children.

◆ GWEN_XMLNode_dup()

GWENHYWFAR_API GWEN_XMLNODE* GWEN_XMLNode_dup ( const GWEN_XMLNODE n)

Create and return a deep copy of the given node.

◆ GWEN_XMLNode_ExpandProperties()

GWENHYWFAR_API int GWEN_XMLNode_ExpandProperties ( const GWEN_XMLNODE tn,
GWEN_DB_NODE dbVars 
)

Expand values of the properties in the given XML node.

If a property contains something like "$(variableName)" then a variable with that name is looked up in the given dbVars and inserted instead of the variable name spec. Internally calls GWEN_DB_ReplaceVars().

◆ GWEN_XMLNode_FindFirstTag()

GWENHYWFAR_API GWEN_XMLNODE* GWEN_XMLNode_FindFirstTag ( const GWEN_XMLNODE n,
const char *  tname,
const char *  pname,
const char *  pvalue 
)

Searches for the first matching tag/element below the given one. Lets say you have the following XML file:

<DEVICES>
<DEVICE id="dev1" />
<DEVICE id="dev2" />
</DEVICES>

If you are looking for a device called "dev2" then you should call this function like this:

tag=GWEN_XMLNode_FindFirstTag(root, "DEVICE", "id", "dev2");
GWENHYWFAR_API GWEN_XMLNODE * GWEN_XMLNode_FindFirstTag(const GWEN_XMLNODE *n, const char *tname, const char *pname, const char *pvalue)
Returns
pointer to the tag/element if found, 0 otherwise
Parameters
ntag/element below which to search
tnametag/element name (e.g. if the tag is "<TESTTAG>" then the tag name is "TESTTAG"). Wildcards (like "*") are allowed.
pnamename of the property/attribute to check (if 0 then no property/attribute comparison takes place). No wildcards allowed.
pvalueoptional value of the property/attribute to compare against, wildcards allowed.

◆ GWEN_XMLNode_FindNameSpaceByName()

GWENHYWFAR_API GWEN_XMLNODE_NAMESPACE* GWEN_XMLNode_FindNameSpaceByName ( const GWEN_XMLNODE n,
const char *  s 
)

◆ GWEN_XMLNode_FindNameSpaceByUrl()

GWENHYWFAR_API GWEN_XMLNODE_NAMESPACE* GWEN_XMLNode_FindNameSpaceByUrl ( const GWEN_XMLNODE n,
const char *  s 
)

◆ GWEN_XMLNode_FindNextTag()

GWENHYWFAR_API GWEN_XMLNODE* GWEN_XMLNode_FindNextTag ( const GWEN_XMLNODE n,
const char *  tname,
const char *  pname,
const char *  pvalue 
)

Searches for the next matching tag/element after the given one one the same level (i.e. the returned element has the same parent node as the given element).

◆ GWEN_XMLNode_FindNode()

GWENHYWFAR_API GWEN_XMLNODE* GWEN_XMLNode_FindNode ( const GWEN_XMLNODE n,
GWEN_XMLNODE_TYPE  t,
const char *  data 
)

This is a very primitive function. It looks for a node of the given type and data matching the given one (case-insensitive) below the given node (i.e. if a node is returned it will be a child of the given one).

◆ GWEN_XMLNode_free()

GWENHYWFAR_API void GWEN_XMLNode_free ( GWEN_XMLNODE n)

Free the given node (including its children nodes)

◆ GWEN_XMLNode_freeAll()

GWENHYWFAR_API void GWEN_XMLNode_freeAll ( GWEN_XMLNODE n)

Free the given node and all nodes besides this one. Hmm, this function should not be public, I think I will move it to xml_p.h.

◆ GWEN_XMLNode_fromString()

GWENHYWFAR_API GWEN_XMLNODE* GWEN_XMLNode_fromString ( const char *  s,
int  len,
uint32_t  flags 
)

◆ GWEN_XMLNode_GetCharValue()

GWENHYWFAR_API const char* GWEN_XMLNode_GetCharValue ( const GWEN_XMLNODE n,
const char *  name,
const char *  defValue 
)

Reads a char value. If no name is given (i.e. name is NULL or empty) then the data returned is that from the first data node below the given node. Otherwise a node with the given name is searched below the given node and its first data node's data is returned.

Parameters
nNode which is expected to contain a node of the specified name
namename of the node below n to be looked up
defValuedefault value to return if the tag did not exist

◆ GWEN_XMLNode_GetCharValueByPath()

GWENHYWFAR_API const char* GWEN_XMLNode_GetCharValueByPath ( GWEN_XMLNODE n,
const char *  path,
const char *  defValue 
)

Return the string value of an element below the given one, specified by an XPath.

Parameters
nNode which is expected to contain the specified path
pathXPath to lookup below the node n
defValuedefault value to return if the tag did not exist

◆ GWEN_XMLNode_GetChild()

GWENHYWFAR_API GWEN_XMLNODE* GWEN_XMLNode_GetChild ( const GWEN_XMLNODE n)

INTERNAL. Descends in the XML tree to the first GWEN_XMLNODE below the given node. The returned node may be a tag/element node, or a property/attribute node, or a data node. You will probably prefer to use GWEN_XMLNode_GetFirstTag() instead of this function.

Returns
The first children tag/element, or NULL if none exists.

◆ GWEN_XMLNode_GetData()

GWENHYWFAR_API const char* GWEN_XMLNode_GetData ( const GWEN_XMLNODE n)

Returns the character data of the given node.

◆ GWEN_XMLNode_GetFirstData()

GWENHYWFAR_API GWEN_XMLNODE* GWEN_XMLNode_GetFirstData ( const GWEN_XMLNODE n)

Descends in the XML tree to the first children data node below the given node.

Different from GWEN_XMLNode_GetChild() this function only looks for another data node and not for a (more general) node.

Returns
The first children data node, or NULL if none exists.

◆ GWEN_XMLNode_GetFirstTag()

GWENHYWFAR_API GWEN_XMLNODE* GWEN_XMLNode_GetFirstTag ( const GWEN_XMLNODE n)

Descends in the XML tree to the first children tag (in XML notation they are called elements) below the given node.

Different from GWEN_XMLNode_GetChild() this function only looks for another tag/element and not for a (more general) node. You will probably prefer this function instead of GWEN_XMLNode_GetChild().

Returns
The first children tag/element, or NULL if none exists.

◆ GWEN_XMLNode_GetHeader()

GWENHYWFAR_API GWEN_XMLNODE* GWEN_XMLNode_GetHeader ( const GWEN_XMLNODE n)

Returns the first header tag of the given node. Use GWEN_XMLNode_Next to get the next header tag.

◆ GWEN_XMLNode_GetIntProperty()

GWENHYWFAR_API int GWEN_XMLNode_GetIntProperty ( const GWEN_XMLNODE n,
const char *  name,
int  defaultValue 
)

Same as GWEN_XMLNode_GetProperty, but it tries to parse the property as an integer value.

◆ GWEN_XMLNode_GetIntValue()

GWENHYWFAR_API int GWEN_XMLNode_GetIntValue ( const GWEN_XMLNODE n,
const char *  name,
int  defValue 
)

Internally calls GWEN_XMLNode_GetCharValue and interpretes the data as an integer which is then returned.

Parameters
nNode which is expected to contain a node of the specified name
namename of the node below n to be looked up
defValuedefault value to return if the tag did not exist

◆ GWEN_XMLNode_GetIntValueByPath()

GWENHYWFAR_API int GWEN_XMLNode_GetIntValueByPath ( GWEN_XMLNODE n,
const char *  name,
int  defValue 
)

Return the integer value of an element below the given one, specified by an XPath.

Parameters
nNode which is expected to contain the specified path
pathXPath to lookup below the node n
defValuedefault value to return if the tag did not exist

◆ GWEN_XMLNode_GetLocalizedCharValue()

GWENHYWFAR_API const char* GWEN_XMLNode_GetLocalizedCharValue ( const GWEN_XMLNODE n,
const char *  name,
const char *  defValue 
)

This function does the same as GWEN_XMLNode_GetCharValue, but it looks for an element with the attribute "lang" which matches the currently selected locale (e.g. "lang=de" for Germany). If there is no localized version of the given element then the first element of that name is used (withouth "lang" attribute). Therefore XML documents used with this function should contain unlocalized elements along with localized ones to provide a fallback.

Parameters
nNode which is expected to contain a node of the specified name
namename of the node below n to be looked up
defValuedefault value to return if the tag did not exist

◆ GWEN_XMLNode_GetNamespace()

GWENHYWFAR_API const char* GWEN_XMLNode_GetNamespace ( const GWEN_XMLNODE n)

◆ GWEN_XMLNode_GetNameSpaces()

GWENHYWFAR_API GWEN_XMLNODE_NAMESPACE_LIST* GWEN_XMLNode_GetNameSpaces ( const GWEN_XMLNODE n)

◆ GWEN_XMLNode_GetNextData()

GWENHYWFAR_API GWEN_XMLNODE* GWEN_XMLNode_GetNextData ( const GWEN_XMLNODE n)

Iterates on the same level in the XML tree from the given data node to the next one on the same level (i.e. the returned element has the same parent node as the given element). An XML element may have multiple data nodes as children, and you use this function to iterate through all of them.

Different from GWEN_XMLNode_Next() this function only looks for another data node and not for a (more general) node.

Returns
The next data node on the same level, or NULL if no more data node exists.

◆ GWEN_XMLNode_GetNextTag()

GWENHYWFAR_API GWEN_XMLNODE* GWEN_XMLNode_GetNextTag ( const GWEN_XMLNODE n)

Iterates on the same level in the XML tree from the given tag (in XML notation they are called elements) to the next one on the same level (i.e. the returned element has the same parent node as the given element).

Different from GWEN_XMLNode_Next() this function only looks for another tag/element and not for a (more general) node. You will probably prefer this function instead of GWEN_XMLNode_Next().

Returns
The next tag/element on the same level, or NULL if no more element exists.

◆ GWEN_XMLNode_GetNodeByXPath()

GWENHYWFAR_API GWEN_XMLNODE* GWEN_XMLNode_GetNodeByXPath ( GWEN_XMLNODE n,
const char *  path,
uint32_t  flags 
)

Locates a tag by its XPath. Currently attributes are not allowed, and the flag GWEN_PATH_FLAGS_VARIABLE is not supported. Supported types of XPaths are:

  • /element[1]/element[2]
  • ../../element[5]

and so on. As you can see index numbers are supported. You should not use this function to create a node but rather for node lookups.

◆ GWEN_XMLNode_GetParent()

GWENHYWFAR_API GWEN_XMLNODE* GWEN_XMLNode_GetParent ( const GWEN_XMLNODE n)

Returns the parent node of the given node, or NULL if it already is the root node.

◆ GWEN_XMLNode_GetProperty()

GWENHYWFAR_API const char* GWEN_XMLNode_GetProperty ( const GWEN_XMLNODE n,
const char *  name,
const char *  defaultValue 
)

Returns the value of the given property/attribute (or the default value if the property/attribute does not exist or is empty).

Parameters
nnode (must be a tag/element)
namename of the property/attribute
defaultValuedefault value to be returned if no value could be retrieved

◆ GWEN_XMLNode_GetType()

GWENHYWFAR_API GWEN_XMLNODE_TYPE GWEN_XMLNode_GetType ( const GWEN_XMLNODE n)

Returns the type of the given node.

◆ GWEN_XMLNode_GetUsage()

GWENHYWFAR_API uint32_t GWEN_XMLNode_GetUsage ( const GWEN_XMLNODE n)

◆ GWEN_XMLNode_GetXPath()

GWENHYWFAR_API int GWEN_XMLNode_GetXPath ( const GWEN_XMLNODE n1,
const GWEN_XMLNODE n2,
GWEN_BUFFER nbuf 
)

◆ GWEN_XMLNode_Globalize()

GWENHYWFAR_API int GWEN_XMLNode_Globalize ( GWEN_XMLNODE n)

◆ GWEN_XMLNode_GlobalizeWithList()

GWENHYWFAR_API int GWEN_XMLNode_GlobalizeWithList ( GWEN_XMLNODE n,
GWEN_XMLNODE_NAMESPACE_LIST l,
uint32_t *  pLastId 
)

◆ GWEN_XMLNode_IncUsage()

GWENHYWFAR_API void GWEN_XMLNode_IncUsage ( GWEN_XMLNODE n)

◆ GWEN_XMLNode_IsChildOf()

GWENHYWFAR_API int GWEN_XMLNode_IsChildOf ( const GWEN_XMLNODE parent,
const GWEN_XMLNODE child 
)

Checks whether the second node is a child of the first one.

Returns
0 if statement is not true, !=0 otherwise

◆ GWEN_XMLNode_NameSpace_dup()

GWENHYWFAR_API GWEN_XMLNODE_NAMESPACE* GWEN_XMLNode_NameSpace_dup ( const GWEN_XMLNODE_NAMESPACE ns)

◆ GWEN_XMLNode_NameSpace_free()

GWENHYWFAR_API void GWEN_XMLNode_NameSpace_free ( GWEN_XMLNODE_NAMESPACE ns)

◆ GWEN_XMLNode_NameSpace_GetName()

GWENHYWFAR_API const char* GWEN_XMLNode_NameSpace_GetName ( const GWEN_XMLNODE_NAMESPACE ns)

◆ GWEN_XMLNode_NameSpace_GetUrl()

GWENHYWFAR_API const char* GWEN_XMLNode_NameSpace_GetUrl ( const GWEN_XMLNODE_NAMESPACE ns)

◆ GWEN_XMLNode_NameSpace_new()

GWENHYWFAR_API GWEN_XMLNODE_NAMESPACE* GWEN_XMLNode_NameSpace_new ( const char *  name,
const char *  url 
)

◆ GWEN_XMLNode_new()

GWENHYWFAR_API GWEN_XMLNODE* GWEN_XMLNode_new ( GWEN_XMLNODE_TYPE  t,
const char *  data 
)

◆ GWEN_XMLNode_Next()

GWENHYWFAR_API GWEN_XMLNODE* GWEN_XMLNode_Next ( const GWEN_XMLNODE n)

INTERNAL. Iterates on the same level in the XML tree from the given node to the next one on the same level (i.e. the returned node has the same parent node as the given element). The returned node may be a tag/element node, or a property/attribute node, or a data node. You will probably prefer to use GWEN_XMLNode_GetNextTag() instead of this function.

Returns
The next node on the same level, or NULL if no more element exists.

◆ GWEN_XMLNode_NormalizeNameSpaces()

GWENHYWFAR_API int GWEN_XMLNode_NormalizeNameSpaces ( GWEN_XMLNODE n)

This function removes unnecessary namespaces from the given node and all nodes below.

◆ GWEN_XMLNode_Path_Dive()

GWENHYWFAR_API int GWEN_XMLNode_Path_Dive ( GWEN_XMLNODE_PATH np,
GWEN_XMLNODE n 
)

Adds a node to the path.

◆ GWEN_XMLNode_Path_Dump()

GWENHYWFAR_API void GWEN_XMLNode_Path_Dump ( GWEN_XMLNODE_PATH np)

Dumps the contents of all XML nodes in the path.

◆ GWEN_XMLNode_Path_dup()

GWENHYWFAR_API GWEN_XMLNODE_PATH* GWEN_XMLNode_Path_dup ( const GWEN_XMLNODE_PATH np)

◆ GWEN_XMLNode_Path_free()

GWENHYWFAR_API void GWEN_XMLNode_Path_free ( GWEN_XMLNODE_PATH np)

◆ GWEN_XMLNode_Path_new()

GWENHYWFAR_API GWEN_XMLNODE_PATH* GWEN_XMLNode_Path_new ( void  )

◆ GWEN_XMLNode_Path_Surface()

GWENHYWFAR_API GWEN_XMLNODE* GWEN_XMLNode_Path_Surface ( GWEN_XMLNODE_PATH np)

Removes and returns the last added node (or 0 if that would bring us beyond the root).

◆ GWEN_XMLNode_RemoveChildren()

GWENHYWFAR_API void GWEN_XMLNode_RemoveChildren ( GWEN_XMLNODE n)

Unlinks and frees all children of the given node.

◆ GWEN_XMLNode_SetCharValue()

GWENHYWFAR_API void GWEN_XMLNode_SetCharValue ( GWEN_XMLNODE n,
const char *  name,
const char *  value 
)

◆ GWEN_XMLNode_SetCharValueByPath()

GWENHYWFAR_API int GWEN_XMLNode_SetCharValueByPath ( GWEN_XMLNODE n,
uint32_t  flags,
const char *  name,
const char *  value 
)

◆ GWEN_XMLNode_SetData()

GWENHYWFAR_API void GWEN_XMLNode_SetData ( GWEN_XMLNODE n,
const char *  data 
)

Set the character data of the given node to the given value. This function will create a deep copy of the character data.

◆ GWEN_XMLNode_SetIntProperty()

GWENHYWFAR_API void GWEN_XMLNode_SetIntProperty ( GWEN_XMLNODE n,
const char *  name,
int  value 
)

Same as GWEN_XMLNode_SetProperty, but for integer values.

◆ GWEN_XMLNode_SetIntValue()

GWENHYWFAR_API void GWEN_XMLNode_SetIntValue ( GWEN_XMLNODE n,
const char *  name,
int  value 
)

◆ GWEN_XMLNode_SetIntValueByPath()

GWENHYWFAR_API int GWEN_XMLNode_SetIntValueByPath ( GWEN_XMLNODE n,
uint32_t  flags,
const char *  name,
int  value 
)

◆ GWEN_XMLNode_SetNamespace()

GWENHYWFAR_API void GWEN_XMLNode_SetNamespace ( GWEN_XMLNODE n,
const char *  s 
)

◆ GWEN_XMLNode_SetProperty()

GWENHYWFAR_API void GWEN_XMLNode_SetProperty ( GWEN_XMLNODE n,
const char *  name,
const char *  value 
)

Sets the value of a property/attribute. This property/attribute will be created if it does not exist and overwritten if it does.

Parameters
nnode (must be a tag/element)
namename of the property/attribute
valuenew value of the property/attribute

◆ GWEN_XMLNode_StripNamespaces()

GWENHYWFAR_API int GWEN_XMLNode_StripNamespaces ( GWEN_XMLNODE n)

◆ GWEN_XMLNode_toBuffer()

GWENHYWFAR_API int GWEN_XMLNode_toBuffer ( const GWEN_XMLNODE n,
GWEN_BUFFER buf,
uint32_t  flags 
)

◆ GWEN_XMLNode_UnlinkChild()

GWENHYWFAR_API void GWEN_XMLNode_UnlinkChild ( GWEN_XMLNODE n,
GWEN_XMLNODE child 
)

Unlinks the given child node from its parent without freeing it. This function relinquishes the ownership of the child to the caller who thereby becomes responsible for freeing this node.

Parameters
nnode which is suspected to be the parent of the second argument
childnode which is to be unlinked

◆ GWEN_XMLNode_WriteFile()

GWENHYWFAR_API int GWEN_XMLNode_WriteFile ( const GWEN_XMLNODE n,
const char *  fname,
uint32_t  flags 
)

Writes a tag and all its subnodes to the given file.

◆ GWEN_XMLNode_WriteToStream()

GWENHYWFAR_API int GWEN_XMLNode_WriteToStream ( const GWEN_XMLNODE n,
GWEN_XML_CONTEXT ctx,
GWEN_SYNCIO sio 
)

Writes a tag and all its subnodes to the given io layer.