Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[044716]: contrib / brl / b3p / expatpp / SimpleTest / SimpleTest.cpp Maximize Restore History

Download this file

SimpleTest.cpp    90 lines (76 with data), 1.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// SimpleTest.cpp : Defines the entry point for the console application.
//
#include "StdAfx.h"
#include <vcl_cstdio.h>
#include <expatpplib.h> // resides in b3p/expatpp
#include <vcl_cstring.h>
class myParser : public expatpp
{
public: myParser() : mDepth(0) {}
virtual void startElement(const XML_Char *name, const XML_Char **atts);
virtual void endElement(const XML_Char* name);
virtual void charData(const XML_Char *s, int len);
private:
void WriteIndent();
int mDepth;
};
void myParser::WriteIndent()
{
for (int i=0; i<mDepth; i++)
vcl_putchar('\t');
}
void myParser::startElement(const char* name, const char** atts)
{
WriteIndent();
vcl_puts(name);
if (atts) { /* write list of attributes indented below element */
int i;
for (i=0; atts[i]; i++) {
WriteIndent();
vcl_putchar('-'); vcl_putchar(' ');
vcl_puts(atts[i]);
}
}
mDepth++;
}
void myParser::endElement(const char*)
{
mDepth--;
}
void myParser::charData(const XML_Char *s, int len)
{
const int leadingSpace = skipWhiteSpace(s);
if (len==0 || len==leadingSpace)
return; // called with whitespace between elements
WriteIndent();
/* write out the user data bracketed by ()*/
vcl_putchar('(');
vcl_fwrite(s, len, 1, stdout);
vcl_puts(")");
}
int main(int argc, char* argv[])
{
myParser parser;
char filename[80];
FILE* xmlFile;
for (;;) {
int depth = 0;
vcl_puts("\n\nXML test: enter filename");
vcl_gets(filename);
if (vcl_strlen(filename)==0)
break;
xmlFile = vcl_fopen(filename, "r");
if (!xmlFile)
break;
if (!parser.parseFile(xmlFile)) {
vcl_fprintf(stderr,
"%s at line %d\n",
XML_ErrorString(parser.XML_GetErrorCode()),
parser.XML_GetCurrentLineNumber()
);
return 1;
}
} // loop asking for and parsing files
vcl_puts("\nfinished!");
return 0;
}