ReactOS 0.4.15-dev-7934-g1dc8d80
XMLStorage::XMLReaderBase Struct Referenceabstract

XML reader base class. More...

#include <xmlstorage.h>

Inheritance diagram for XMLStorage::XMLReaderBase:
Collaboration diagram for XMLStorage::XMLReaderBase:

Public Member Functions

 XMLReaderBase (XMLNode *node)
 
virtual ~XMLReaderBase ()
 
bool parse ()
 
void read ()
 read XML stream into XML tree below _pos
 
std::string get_position () const
 return current parser position as string
 
const XMLFormatget_format () const
 
const charget_endl () const
 
const XMLErrorListget_errors () const
 
const XMLErrorListget_warnings () const
 
void clear_errors ()
 

Protected Types

enum  { TAG_NONE , TAG_START , TAG_END }
 

Protected Member Functions

virtual int get ()=0
 
int eat_endl ()
 
void finish_read ()
 
virtual void XmlDeclHandler (const char *version, const char *encoding, int standalone)
 store XML version and encoding into XML reader
 
virtual void StartElementHandler (const XS_String &name, const XMLNode::AttributeMap &attributes)
 notifications about XML start tag
 
virtual void EndElementHandler ()
 notifications about XML end tag
 
virtual void DefaultHandler (const std::string &s)
 store content, white space and comments
 

Protected Attributes

XMLPos _pos
 
std::string _content
 
enum XMLStorage::XMLReaderBase:: { ... }  _last_tag
 
XMLErrorList _errors
 
XMLErrorList _warnings
 
XMLFormat _format
 
bool _endl_defined
 
bool _utf8
 

Detailed Description

XML reader base class.

Definition at line 2414 of file xmlstorage.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected
Enumerator
TAG_NONE 
TAG_START 
TAG_END 

Definition at line 2506 of file xmlstorage.h.

Constructor & Destructor Documentation

◆ XMLReaderBase()

XMLStorage::XMLReaderBase::XMLReaderBase ( XMLNode node)
inline

Definition at line 2464 of file xmlstorage.h.

2465 : _pos(node),
2466 _endl_defined(false),
2467 _utf8(false)
2468 {
2470 }
Definition: dlist.c:348

◆ ~XMLReaderBase()

XMLStorage::XMLReaderBase::~XMLReaderBase ( )
virtual

Definition at line 54 of file xs-native.cpp.

55{
56}

Member Function Documentation

◆ clear_errors()

void XMLStorage::XMLReaderBase::clear_errors ( )
inline

Definition at line 2490 of file xmlstorage.h.

2490{_errors.clear(); _warnings.clear();}

◆ DefaultHandler()

void XMLStorage::XMLReaderBase::DefaultHandler ( const std::string &  s)
protectedvirtual

store content, white space and comments

Definition at line 434 of file xs-native.cpp.

435{
436 _content.append(s);
437}
GLdouble s
Definition: gl.h:2039

◆ eat_endl()

int XMLStorage::XMLReaderBase::eat_endl ( )
protected

Definition at line 389 of file xs-native.cpp.

390{
391 int c = get();
392
393 if (c == '\r')
394 c = get();
395
396 if (c == '\n')
397 c = get();
398
399 return c;
400}
const GLubyte * c
Definition: glext.h:8905
#define c
Definition: ke_i.h:80

Referenced by parse().

◆ EndElementHandler()

void XMLStorage::XMLReaderBase::EndElementHandler ( )
protectedvirtual

notifications about XML end tag

Definition at line 899 of file xmlstorage.cpp.

900{
901 const char* s = _content.c_str();
902 const char* e = s + _content.length();
903 const char* p;
904
905 if (!strncmp(s,CDATA_START,9) && !strncmp(e-3,CDATA_END,3)) {
906 s += 9;
907 p = (e-=3);
908
909 _pos->_cdata_content = true;
910 } else {
911 // search for content end leaving only white space for _end_leading
912 for(p=e; p>s; --p)
913 if (!isspace((unsigned char)p[-1]))
914 break;
915
916 _pos->_cdata_content = false;
917 }
918
919 if (p != s) {
920 if (_pos->_children.empty()) // no children in current node?
921 _pos->_content.append(s, p-s);
922 else if (_last_tag == TAG_START)
923 _pos->_content.append(s, p-s);
924 else
925 _pos->_children.back()->_trailing.append(s, p-s);
926 }
927
928 if (p != e)
929 _pos->_end_leading.assign(p, e-p);
930
931 _pos.back();
932
934 _content.erase();
935}
#define isspace(c)
Definition: acclib.h:69
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
GLfloat GLfloat p
Definition: glext.h:8902
#define e
Definition: ke_i.h:82
std::string _content
Definition: xmlstorage.h:1274
std::string _end_leading
Definition: xmlstorage.h:1275
bool back()
go back to previous position
Definition: xmlstorage.h:1581
#define CDATA_START
Definition: xmlstorage.h:435
#define CDATA_END
Definition: xmlstorage.h:436

Referenced by parse().

◆ finish_read()

void XMLStorage::XMLReaderBase::finish_read ( )
protected

Definition at line 831 of file xmlstorage.cpp.

832{
833 if (_pos->_children.empty())
834 _pos->_trailing.append(_content);
835 else
836 _pos->_children.back()->_trailing.append(_content);
837
838 _content.erase();
839}
std::string _trailing
Definition: xmlstorage.h:1276

Referenced by read().

◆ get()

virtual int XMLStorage::XMLReaderBase::get ( )
protectedpure virtual

Implemented in XMLStorage::XMLReader.

Referenced by eat_endl(), and parse().

◆ get_endl()

const char * XMLStorage::XMLReaderBase::get_endl ( ) const
inline

Definition at line 2485 of file xmlstorage.h.

2485{return _endl_defined? _format._endl: "\n";}
const char * _endl
Definition: xmlstorage.h:789

◆ get_errors()

const XMLErrorList & XMLStorage::XMLReaderBase::get_errors ( ) const
inline

Definition at line 2487 of file xmlstorage.h.

2487{return _errors;}

◆ get_format()

const XMLFormat & XMLStorage::XMLReaderBase::get_format ( ) const
inline

Definition at line 2484 of file xmlstorage.h.

2484{return _format;}

◆ get_position()

std::string XMLStorage::XMLReaderBase::get_position ( ) const

return current parser position as string

Definition at line 403 of file xs-native.cpp.

404{
405/*@TODO display parser position in case of errors
406 int line = XML_GetCurrentLineNumber(_parser);
407 int column = XML_GetCurrentColumnNumber(_parser);
408
409 std::ostringstream out;
410 out << "(" << line << ") : [column " << column << "]";
411
412 return out.str();
413*/
414 return "";
415}

◆ get_warnings()

const XMLErrorList & XMLStorage::XMLReaderBase::get_warnings ( ) const
inline

Definition at line 2488 of file xmlstorage.h.

2488{return _warnings;}

◆ parse()

bool XMLStorage::XMLReaderBase::parse ( )

Definition at line 226 of file xs-native.cpp.

227{
229 int c = get();
230 bool in_comment = false;
231
232 while(c != EOF) {
233 if (in_comment || c=='<') {
234 buffer.append(c);
235
236 // read start or end tag
237 for(;;) {
238 c = get();
239
240 if (c == EOF)
241 break;
242
243 buffer.append(c);
244
245 if (c == '>')
246 break;
247 }
248
249 const std::string& b = buffer.str(_utf8);
250 const char* str = b.c_str();
251
252 if (in_comment || !strncmp(str+1, "!--", 3)) {
253 // XML comment
255
256 if (strcmp(str+b.length()-3, "-->"))
257 in_comment = true;
258 else
259 in_comment = false;
260
261 c = get();
262 } else if (str[1] == '/') {
263 // end tag
264
265 /*@TODO error handling
266 const XS_String& tag = buffer.get_tag();
267
268 if (tag != last_opened_tag) {
269 ERROR
270 }
271 */
272
274
275 c = get();
276 } else if (str[1] == '?') {
277 // XML declaration
278 const XS_String& tag = buffer.get_tag();
279
280 if (tag == "?xml") {
281 XMLNode::AttributeMap attributes;
282 buffer.get_attributes(attributes);
283
284 const std::string& version = attributes.get("version");
285 const std::string& encoding = attributes.get("encoding");
286
287 int standalone;
288 XMLNode::AttributeMap::const_iterator found = // const_cast for ISO C++ compatibility error of GCC
289 const_cast<const XMLNode::AttributeMap&>(attributes).find("standalone");
290 if (found != attributes.end())
291 standalone = !XS_icmp(found->second.c_str(), XS_TEXT("yes"));
292 else
293 standalone = -1;
294
295 XmlDeclHandler(version.empty()?NULL:version.c_str(), encoding.empty()?NULL:encoding.c_str(), standalone);
296
297 if (!encoding.empty() && !_stricmp(encoding.c_str(), "utf-8"))
298 _utf8 = true;
299
300 c = eat_endl();
301 } else if (tag == "?xml-stylesheet") {
302 XMLNode::AttributeMap attributes;
303 buffer.get_attributes(attributes);
304
305 StyleSheet stylesheet(attributes.get("href"), attributes.get("type"), !XS_icmp(attributes.get("alternate"), XS_TEXT("yes")));
306 stylesheet._title = attributes.get("title");
307 stylesheet._media = attributes.get("media");
308 stylesheet._charset = attributes.get("charset");
309
310 _format._stylesheets.push_back(stylesheet);
311
312 c = eat_endl();
313 } else {
315 c = get();
316 }
317 } else if (str[1] == '!') {
318 if (!strncmp(str+2, "DOCTYPE ", 8)) {
320
321 c = eat_endl();
322 } else if (!strncmp(str+2, "[CDATA[", 7)) { // see CDATA_START
323 // parse <![CDATA[ ... ]]> strings
324 while(!buffer.has_CDEnd()) {
325 c = get();
326
327 if (c == EOF)
328 break;
329
330 buffer.append(c);
331 }
332
334
335 c = get();
336 }
337 } else {
338 // start tag
339 const XS_String& tag = buffer.get_tag();
340
341 if (!tag.empty()) {
342 XMLNode::AttributeMap attributes;
343 buffer.get_attributes(attributes);
344
345 StartElementHandler(tag, attributes);
346
347 if (str[b.length()-2] == '/')
349 }
350
351 c = get();
352 }
353 } else {
354 buffer.append(c);
355
356 // read white space
357 for(;;) {
358 // check for the encoding of the first line end
359 if (!_endl_defined) {
360 if (c == '\n') {
361 _format._endl = "\n";
362 _endl_defined = true;
363 } else if (c == '\r') {
364 _format._endl = "\r\n";
365 _endl_defined = true;
366 }
367 }
368
369 c = get();
370
371 if (c == EOF)
372 break;
373
374 if (c == '<')
375 break;
376
377 buffer.append(c);
378 }
379
381 }
382
383 buffer.reset();
384 }
385
386 return true; //TODO return false on invalid XML
387}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define _stricmp
Definition: cat.c:22
Definition: bufpool.h:45
static TAGID TAGID find
Definition: db.cpp:155
#define NULL
Definition: types.h:112
static const WCHAR version[]
Definition: asmname.c:66
GLuint buffer
Definition: glext.h:5915
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define EOF
Definition: stdio.h:24
const WCHAR * str
void parse(const char *str)
Definition: xmlstorage.cpp:698
StyleSheetList _stylesheets
Definition: xmlstorage.h:796
virtual void StartElementHandler(const XS_String &name, const XMLNode::AttributeMap &attributes)
notifications about XML start tag
Definition: xmlstorage.cpp:856
virtual void XmlDeclHandler(const char *version, const char *encoding, int standalone)
store XML version and encoding into XML reader
Definition: xmlstorage.cpp:843
virtual void EndElementHandler()
notifications about XML end tag
Definition: xmlstorage.cpp:899
Definition: ecma_167.h:138
static char * encoding
Definition: xmllint.c:155
#define XS_TEXT(x)
Definition: xmlstorage.h:237
#define XS_icmp
Definition: xmlstorage.h:241

Referenced by read().

◆ read()

void XMLStorage::XMLReaderBase::read ( )

read XML stream into XML tree below _pos

Definition at line 59 of file xs-native.cpp.

60{
61 if (!parse()) {
63
64 error._message = "XML parsing error";
65 //error._line = ;
66 //error._column = ;
67
68 _errors.push_back(error);
69 }
70
72}
#define error(str)
Definition: mkdosfs.c:1605

◆ StartElementHandler()

void XMLStorage::XMLReaderBase::StartElementHandler ( const XS_String name,
const XMLNode::AttributeMap attributes 
)
protectedvirtual

notifications about XML start tag

Definition at line 856 of file xmlstorage.cpp.

857{
858 const char* s = _content.c_str();
859 const char* e = s + _content.length();
860 const char* p = s;
861
862 // search for content end leaving only white space for leading
863 for(p=e; p>s; --p)
864 if (!isspace((unsigned char)p[-1]))
865 break;
866
867 if (p != s) {
868 if (_pos->_children.empty()) { // no children in last node?
869 if (_last_tag == TAG_START)
870 _pos->_content.append(s, p-s);
871 else if (_last_tag == TAG_END)
872 _pos->_trailing.append(s, p-s);
873 else // TAG_NONE at root node
874 p = s;
875 } else
876 _pos->_children.back()->_trailing.append(s, p-s);
877 }
878
879 std::string leading;
880
881 if (p != e)
882 leading.assign(p, e-p);
883
884 XMLNode* node = new XMLNode(name, leading);
885
887
888#ifdef XMLNODE_LOCATION
889 node->_location = get_location();
890#endif
891
892 node->_attributes = attributes;
893
895 _content.erase();
896}
static HRESULT get_location(HTMLInnerWindow *This, HTMLLocation **ret)
Definition: htmlwindow.c:43
void assign(Children &other)
Definition: xmlstorage.h:923
void add_down(XMLNode *child)
insert children when building tree
Definition: xmlstorage.h:1574
Definition: name.c:39

Referenced by parse().

◆ XmlDeclHandler()

void XMLStorage::XMLReaderBase::XmlDeclHandler ( const char version,
const char encoding,
int  standalone 
)
protectedvirtual

store XML version and encoding into XML reader

Definition at line 843 of file xmlstorage.cpp.

844{
845 if (version)
847
848 if (encoding)
850
851 _format._standalone = standalone;
852}
std::string _encoding
Definition: xmlstorage.h:792
std::string _version
Definition: xmlstorage.h:791

Referenced by parse().

Member Data Documentation

◆ _content

std::string XMLStorage::XMLReaderBase::_content
protected

Definition at line 2505 of file xmlstorage.h.

Referenced by DefaultHandler(), EndElementHandler(), finish_read(), and StartElementHandler().

◆ _endl_defined

bool XMLStorage::XMLReaderBase::_endl_defined
protected

Definition at line 2512 of file xmlstorage.h.

Referenced by get_endl(), and parse().

◆ _errors

XMLErrorList XMLStorage::XMLReaderBase::_errors
protected

Definition at line 2508 of file xmlstorage.h.

Referenced by clear_errors(), get_errors(), and read().

◆ _format

XMLFormat XMLStorage::XMLReaderBase::_format
protected

Definition at line 2511 of file xmlstorage.h.

Referenced by get_endl(), get_format(), parse(), and XmlDeclHandler().

◆ 

enum { ... } XMLStorage::XMLReaderBase::_last_tag

◆ _pos

XMLPos XMLStorage::XMLReaderBase::_pos
protected

Definition at line 2503 of file xmlstorage.h.

Referenced by EndElementHandler(), finish_read(), and StartElementHandler().

◆ _utf8

bool XMLStorage::XMLReaderBase::_utf8
protected

Definition at line 2522 of file xmlstorage.h.

Referenced by parse().

◆ _warnings

XMLErrorList XMLStorage::XMLReaderBase::_warnings
protected

Definition at line 2509 of file xmlstorage.h.

Referenced by clear_errors(), and get_warnings().


The documentation for this struct was generated from the following files: