/* * libwbxml, the WBXML Library. * Copyright (C) 2002-2005 Aymerick Jehanne * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * LGPL v2.1: http://www.gnu.org/copyleft/lesser.txt * * Contact: libwbxml@aymerick.com * Home: http://libwbxml.aymerick.com */ /** * @file test_parser.c * @ingroup test * * @author Aymerick Jéhanne * @date 03/03/21 * * @brief Test the WBXML Parser */ #include #include #define INPUT_BUFFER_SIZE 1000 /** Start Document Callback */ void parse_clb_start_document(void *ctx, WB_LONG charset, const WBXMLLangEntry *lang) { printf("Parsing Document:\n" "\tRoot Element: %s\n" "\tPublic ID: %s\n" "\tDTD: %s\n", lang->publicID->xmlRootElt, lang->publicID->xmlPublicID, lang->publicID->xmlDTD); } /** End Document Callback */ void parse_clb_end_document(void *ctx) { printf("End of Document\n"); } /** Start Element Callback */ void parse_clb_start_element(void *ctx, WBXMLTag *element, WBXMLAttribute **atts, WB_BOOL empty) { WB_ULONG *indent = (WB_ULONG *) ctx; WB_ULONG i = 0, j = 0; /* Indent start Element */ for (i=0; i<*indent; i++) printf(" "); /* Write start Element */ printf("<%s", wbxml_tag_get_xml_name(element)); /* Write Attributes */ if (atts != NULL) { while (atts[j] != NULL) { /* Write Attribute Name */ printf(" %s=\"%s\"", wbxml_attribute_get_xml_name(atts[j]), wbxml_attribute_get_xml_value(atts[j])); j++; } } /* End of start Element */ if (empty) { printf("/>\n"); } else { printf(">\n"); (*indent)++; } } /** End Element Callback */ void parse_clb_end_element(void *ctx, WBXMLTag *element, WB_BOOL empty) { WB_ULONG *indent = (WB_ULONG *) ctx; WB_ULONG i = 0; if (!empty) { (*indent)--; /* Indent End Element */ for (i=0; i<*indent; i++) printf(" "); /* Write end tag */ printf("\n", wbxml_tag_get_xml_name(element)); } } /** Characters Callback */ void parse_clb_characters(void *ctx, WB_UTINY *ch, WB_ULONG start, WB_ULONG length) { WB_ULONG *indent = (WB_ULONG *) ctx; WB_ULONG i = 0; /* Indent Characters */ for (i=0; i<*indent; i++) printf(" "); /* Write Content */ for(i=start; i