Wildcat- Simple "C" XML reader Code
Wildcat: Simple "C" XML reader
Status: Beta
Brought to you by:
l-crisan
File | Date | Author | Commit |
---|---|---|---|
include | 2024-01-29 | l-crisan | [r5] Cleanup/Bug fixing |
src | 2024-03-12 | l-crisan | [r7] bug fix |
Readme.md | 2024-01-29 | l-crisan | [r5] Cleanup/Bug fixing |
main.cpp | 2024-01-29 | l-crisan | [r5] Cleanup/Bug fixing |
#include <wildcat/xml/Reader.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char* xmlData = "<?xml version = \"1.0\" encoding = \"UTF-8\" ?>\n"
"<test/>\n"
"<Comment>\n"
"<![CDATA[0x0001 = Toggle Bit : 1. EtherCAT command received new inputs\n"
"0x0002 = Toggle Bit : 2. EtherCAT command received new inputs\n"
"0x0004 = Toggle Bit : 3. EtherCAT command received new inputs\n"
"...\n"
"0x4000 = Toggle Bit : 15. EtherCAT command received new inputs\n"
"0x8000 = Old frame - not from the actual cycle - received\n"
"]]>"
"</Comment>"
"<a>\n"
"<b>142</b>\n"
"<g>2626</g>\n"
"</a>";
int main(int argc, char* argv[])
{
wcxml_Iterator* context = wcxml_Reader_loadDocument(xmlData, strlen(xmlData), true, true);
//wcxml_Iterator* context = wcxml_Reader_openDocument("test.xml");
const char* header = wcxml_Reader_getHeader(context);
printf("<?xml %s ?>\n", header);
bool r = wcxml_Reader_begin(context);
while (r)
{
switch (wcxml_Reader_getType(context))
{
case wcxml_Type_EmptyElement:
printf("<%s/>\n", wcxml_Reader_getName(context));
break;
case wcxml_Type_StartElement:
printf("<%s>\n", wcxml_Reader_getName(context));
for (int i = 0; i < wcxml_Reader_getAttrCount(context); ++i)
printf("%s =%s\n", wcxml_Reader_getAttrName(context, i), wcxml_Reader_getAttrValue(context, i));
break;
case wcxml_Type_Comment:
printf("<!--%s-->\n", wcxml_Reader_getContent(context));
break;
case wcxml_Type_Content:
printf("%s\n", wcxml_Reader_getContent(context));
break;
case wcxml_Type_EndElement:
printf("</%s>\n", wcxml_Reader_getName(context));
break;
}
r = wcxml_Reader_next(context);
}
wcxml_Reader_closeDocument(context);
}