/******************************************************************************* * TestParser * * This is a test function to verify that the library is properly opening and * reading xml files. ******************************************************************************/ DLLIMPORT void TestParser( char *Filename ) { scew_parser *parser; scew_element *params; int elementCount = 0; int i; char Buffer[1024]; parser = scew_parser_create (); if (parser != NULL) { scew_parser_load_file (parser, Filename); params = scew_tree_root (scew_parser_tree (parser)); elementCount = scew_element_count (params); sprintf(Buffer, "Root has %u children\n", elementCount); MessageBox( 0, Buffer, "Debugging", MB_ICONINFORMATION ); for (i = 0; i < elementCount; i++) { scew_element *newParams = scew_element_by_index (params, i); sprintf(Buffer, "This child has %u subchildren\n", scew_element_count( newParams )); MessageBox( 0, Buffer, "Debugging", MB_ICONINFORMATION ); sprintf(Buffer, "Child %i name='%s'\n", i, scew_element_name (scew_element_by_index (params, i))); MessageBox( 0, Buffer, "Debugging", MB_ICONINFORMATION ); } scew_parser_free( parser ); } }
/******************************************************************************* * Function: Element_By_Index * * This function returns a void * representing a pointer to a valid * scew_element structure, which is the Index(th) child element of the input * parameter _element, or a NULL pointer on error. * * Parameters: * _element: A void * representing a valid pointer to a scew_element * structure. This pointer must have been created previously by * some other function in this library. * Index: An integer value, zero based, representing the index of the * child element of _element. * * Returns: * void *: Representing a pointer to a scew_element structure, which is the * Index(th) child element of _element. * A NULL value is returned on error. * ******************************************************************************/ DLLIMPORT void *Element_By_Index( void *_element, int Index ) { void *ret_val = NULL; if (( _element != NULL ) && (Index >= 0 )) { ret_val = scew_element_by_index (_element, Index); }; return ret_val; }
/******************************************************************************* * Function: Element_Name_By_Index * * This function returns a char * representing a pointer to the name of the * element specified as the Index(th) child of the input parameter _element. * * Parameters: * _element: A void * representing a valid pointer to a scew_element * structure. This pointer must have been created previously by * some other function in this library. * Index: An integer value, zero based, representing the index of the * child element of _element. * * Returns: * char *: Representing a pointer to a NULL terminated character array, * which contains the name of the element established by the Index(th) * child element of _element. A NULL value is returned on error. * ******************************************************************************/ DLLIMPORT char *Element_Name_By_Index(void *_element, int Index) { char *ret_val = NULL; if (( _element != NULL ) && ( Index >=0 )) { scew_element *temp = scew_element_by_index((scew_element *)_element, Index); if ( temp != NULL ) ret_val = (char *)scew_element_name( temp ); }; return ret_val; }
void scew_element_del_by_index(scew_element* element, unsigned int idx) { scew_element_free(scew_element_by_index(element, idx)); }