Menu

Home

Charles Oehmke

For general information about btrxml, check the website:
http://eonedgestudios.com/btrxml/btrxml.html

The best way to learn how to use btrxml is to probably read through the accompanying header file. At the bottom are 6 function declarations that should be of particular interest.

Quick example of how to parse an XML file in C:

bxDocument xdoc;
bxNode* myNode = NULL;

if (bxParseFile(&xdoc, "myxml.xml") == 0)
{
    myNode = bxFindChildNodeByTag(xdoc.nodeRoot, "firstchild");
    if (myNode)
    {
        //... do stuff ...
    }
    bxDestroy(&xdoc);
}

Below is a direct extraction from the header file for all the functions used in btrxml.

function prototypes from btrxml.h:

//parses the given filename in to the passed bxDocument structure
//returns number of errors found
extern uint_fast32_t bxParseFile(bxDocument* xdoc, const char* fname);

//parses the given string data in to the passed bxDocument structure
//if this is called directly, the user is responsible for cleaning up
//the string buffer after processing!
//returns number of errors found
extern uint_fast32_t bxParseStr(bxDocument* xdoc, const char* strBuffer);

//will find the first child of nodeParent with strTagToFind as a tag name
//returns NULL if no such child was found
extern bxNode* bxFindChildNodeByTag(bxNode* nodeParent, const char* strTagToFind);

//given some node, will go through all *next* siblings, returning the first one
//matching the strTagtoFind tag name; ideally use this to cycle through all
//siblings to find collections of nodes, eg all <robot>'s
//returns NULL if no sibling was found
extern bxNode* bxFindNextSiblingByTag(bxNode* nodeCurrent, const char* strTagToFind);

//will return a bxAttribute where the name = strName, if it exists.
//returns NULL if not found or node is NULL
extern bxAttribute* bxGetAttributeByName(bxNode* node, const char* strName);

//destroy the DOM-like structure data associated with xdoc
extern uint_fast32_t bxDestroy(bxDocument* xdoc);
Project Admins: