4 * Created on: Apr 17, 2014
8 #include <libxml/parser.h>
9 #include <libxml/tree.h>
11 //>> Forward declaration of xmlNodePtr.
12 typedef struct _xmlNode xmlNode;
13 typedef xmlNode *xmlNodePtr;
17 //>> Forward declaration of xmlDocPtr.
18 typedef struct _xmlDoc xmlDoc;
19 typedef xmlDoc *xmlDocPtr;
24 * Returns true if theNode is XML ELEMENT node (not a "text" node ie).
26 static bool isElementNode(xmlNodePtr theNode)
28 return theNode->type == XML_ELEMENT_NODE;
32 * Returns true if theNode is XML node with a given name.
34 * Please note that this function should be called with NULL last argument.
35 * In example: isNode(aNode, "type1", ["type2", ...], NULL);
36 * ", NULL" is required to use unlimited number of arguments.
37 * TODO(sbh): find a way to simplify calling this method.
39 static bool isNode(xmlNodePtr theNode, const char* theNodeName, ...)
42 const xmlChar* aName = theNode->name;
43 if (!aName || !isElementNode(theNode)) {
46 if (!xmlStrcmp(aName, (const xmlChar *) theNodeName)) {
49 va_list args; // define argument list variable
50 va_start(args, theNodeName); // init list; point to last defined argument
52 char *anArg = va_arg (args, char*); // get next argument
55 if (!xmlStrcmp(aName, (const xmlChar *) anArg)) {
56 va_end(args); // cleanup the system stack
60 va_end(args); // cleanup the system stack
66 * Every xml node has child. Even if there is no explicit
67 * child nodes libxml gives the "Text node" as child.
69 * This method checks if real child nodes exist in the
72 static bool hasChild(xmlNodePtr theNode)
74 xmlNodePtr aNode = theNode->children;
75 for(; aNode; aNode = aNode->next) {
76 if (isElementNode(theNode)) {