forked from andig/canprogs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXmlParser.h
executable file
·106 lines (80 loc) · 3.09 KB
/
XmlParser.h
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
*
* Copyright (C) 2014 Jürg Müller, CH-5524
*
* This program 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 version 3 of the License.
*
* This program 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 program. If not, see http://www.gnu.org/licenses/ .
*/
#ifndef XML_PARSER_H
#define XML_PARSER_H
#include "KXmlNodeList.h"
#include "KStream.h"
#include "NCanUtils.h"
// xml Grammar:
//
// body ::= [comment] "<" Name (attribute)* ( "/>" | ">" (body)* "</" Name ">")
// attribute ::= AttributeId "=" """" Value """"
// alternativ "comment": <!-- comment -->
class KParser : public KStream
{
private:
int mStreamLen; // strlen(mStream)
const char * mStream;// XML stream (0-terminated)
int mActualPos; // actual parser position
int mErrorPos; // error position in mStream
public:
int mRecursionDepth; // recursion depth within xml stream
bool mStatusOk; // parser status
// GetAttribute results
// GetAttribute parses the xml stream
// Attr="Value"
// ^ ^- mValueLen
// +------- mAttribute
int mAttributePos;
int mValuePos;
int mValueLen;
TTagName mAttribute;
// KStringStream mErrorMsg;
KParser();
void GetAttribute();
void GetTagName(int & TagNamePos, TTagName & TagName);
void SetError(int ErrPos);
// init. parser
void Initialize();
// parses header of the form:
// <?xml version="1.0" encoding="UTF-8"?> analysieren.
bool ParseXmlHeader();
// the character at the parser position might not be:
// 0, '/', '>', or '<'
bool IsActualPositionValid();
int GetIdentifier(char * Id, int MaxIdLen);
// skips blanks, line feeds and tabulator characters
char SkipSpaces();
// skips comments
// if the result is true: the next parsing character is an '<'
bool StartNewBody(KXmlNode * NewNode = NULL);
// EinBody sollte mit "</BodyName>" abgeschlossen sein.
void TestBodyEnd(TTagName & TagName);
// it expects Char at the parser position (all other characters are an
// error)
void NeedChar(char Char);
// true, if Char is at the parser position
bool TestChar(char Char);
// "/>": there is not a subbody
// ">": there is a subbody
bool HasSubBody();
bool GenerateFromXml(KXmlNode * Parent);
bool Parse(KXmlNode * Root);
bool ParseFile_(const char * FileName, KXmlNode * Root);
static bool ParseFile(const char * FileName, KXmlNode * Root);
};
#endif