[Axl] Using axl_node_get_content

Steven Starr comtuxaps at gmail.com
Tue Jan 15 04:15:22 CET 2008


I am having some trouble figuring out how to use axl_node_get_content <-- "I
think this is the function i want to use"

What i am trying to do is get the contents of  <child1>Hello</child1>
when i use this peice of code...

// get the first child node and its contents
    node = axl_node_get_first_child (node);
    axl_node_dump(node, &value, NULL);
    printf("Useing the axl_node_get_first_child function. \n");
    printf("%s \n\n", value);

This is the output i get.
<child1>Hello</child1>

What i want to do is just get ...
Hello

If someone could provide and example on how to use "axl_node_get_content"?
i would really appreciate it.

axl version
-----------------------------------------------------------------------
axl-0.4.13.b3178.g3181.tar.gz

test.xml
-------------------------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>

<root>
    <child1>Hello</child1>
    <child2>World</child2>
</root>

parser.c
--------------------------------------------------------------------------

#include <axl.h>
#include <stdio.h>

/*How to compile this code.*/
/* gcc parser.c -o parser -I/usr/include/axl  -laxl -lm */

 int main (int argc, char *argv[])
 {
    axlError **error;

    // top level definitions
    axlDoc *doc = NULL;
    axlNode *node = NULL;
    axlItem *item;
    char *value;

    // initialize axl library
    if (! axl_init ()) {
    // print error message if were unable to initialize axl library
        printf ("Unable to initialize Axl library.\n");
          return -1;
    }

    // open a xml document
    doc = axl_doc_parse_from_file ("test.xml", error);

    // if we can't open xml doc then free axl lib and print error message
    if (doc == NULL) {
        axl_error_free (*error);
    printf ("Unable to to open xml file freeing Axl library.\n");
        return false;
    }

    // get the root node and its contents
    node = axl_doc_get_root(doc);
    axl_node_dump(node, &value, NULL);
    printf("Useing the axl_doc_get_root function. \n");
    printf("%s \n\n", value);

    // get the first child node and its contents
    node = axl_node_get_first_child (node);
    axl_node_dump(node, &value, NULL);
    printf("Useing the axl_node_get_first_child function. \n");
    printf("%s \n\n", value);

    // get the next child node and its contents
    node = axl_node_get_next (node);
    axl_node_dump(node, &value, NULL);
    printf("Useing the axl_node_get_next function \n");
    printf("%s \n\n", value);

    // release the document
    axl_doc_free (doc);
    axl_free (value);

    // cleanup axl library
    axl_end ();

    return true;
 }


Compile parse.c
------------------------------------------------------------------------------------------------------
bash-3.2# gcc parse.c -o parse -I/usr/include/axl -laxl -lm



Output
------------------------------------------------------------------------------------------------------
bash-3.2# ./parse
Useing the axl_doc_get_root function.
<root><child1>Hello</child1><child2>World</child2></root>

Useing the axl_node_get_first_child function.
<child1>Hello</child1>

Useing the axl_node_get_next function
<child2>World</child2>

Thanks Steve :)



More information about the Axl mailing list