-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathXmlInspector.hpp
7126 lines (6461 loc) · 176 KB
/
XmlInspector.hpp
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 2013 Przemek Mazurkiewicz ([email protected])
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef XML_INSPECTOR_HPP__f66b9cdaf20734ef11086d0851a9c563
#define XML_INSPECTOR_HPP__f66b9cdaf20734ef11086d0851a9c563
#include "CharactersReader.hpp"
#include "CharactersWriter.hpp"
#include <string>
#include <ios>
#include <streambuf>
#include <istream>
#include <fstream>
#include <cstdint>
#include <memory>
#include <deque>
#include <stdexcept>
/**
@file XmlInspector.hpp
*/
/**
@brief Main namespace for the XML solutions.
*/
namespace Xml
{
/**
@brief An inspected node type.
*/
enum class Inspected
{
/**
@brief This is returned by the Inspector if an Inspect method has not been called.
*/
None,
/**
@brief A start element tag (for example <tt><mytag></tt> ).
*/
StartTag,
/**
@brief An end element tag (for example <tt></mytag></tt> ).
*/
EndTag,
/**
@brief An empty element tag (for example <tt><mytag /></tt> ).
*/
EmptyElementTag,
/**
@brief A text content of a node.
*/
Text,
/**
@brief A CDATA section (for example <tt><![CDATA[don't touch]]></tt> ).
*/
CDATA,
/**
@brief The XML declaration (for example <tt><?xml version='1.0'?></tt> ).
*/
XmlDeclaration,
/**
@brief A comment (for example <tt><!-- my comment --></tt> ).
*/
Comment,
/**
@brief A processing instruction (for example <tt><?mypi ...?></tt> ).
*/
ProcessingInstruction,
/**
@brief A reference to an entity (for example <tt>&myref;</tt> ).
*/
EntityReference,
/**
@brief A document type declaration (for example <tt><!DOCTYPE...></tt> ).
*/
DocumentType,
/**
@brief White space between markup.
*/
Whitespace
};
/**
@brief Error code.
*/
enum class ErrorCode
{
/**
@brief There is no error.
*/
None,
/**
@brief Stream error has occurred.
*/
StreamError,
/**
@brief Invalid byte sequence. For example
invalid byte order mark (BOM) or alone
surrogate halve in the UTF-16 encoding.
*/
InvalidByteSequence,
/**
@brief Unknown encoding.
*/
UnknownEncoding,
/**
@brief Encoding confusion. For example UTF-8 from a byte order mark,
but UTF-32 in an XML declaration encoding.
*/
EncodingConfusion,
/**
@brief Encoding declaration must precede content
that is not legal UTF-8 or UTF-16.
*/
EncodingDeclarationRequired,
/**
@brief Not allowed characters. For example some characters
outside a root element, where a white spaces are the
only characters allowed.
*/
InvalidSyntax,
/**
@brief Check http://www.w3.org/TR/2008/REC-xml-20081126/#NT-XMLDecl.
*/
InvalidXmlDeclarationLocation,
/**
@brief CDATA section is outside a root element.
Check http://www.w3.org/TR/2008/REC-xml-20081126/#NT-CDSect.
*/
CDataSectionOutside,
/**
@brief Element is outside a root element.
*/
ElementOutside,
/**
@brief Check http://www.w3.org/TR/2008/REC-xml-20081126/#NT-doctypedecl.
*/
InvalidDocumentTypeDeclarationLocation,
/**
@brief Check http://www.w3.org/TR/2008/REC-xml-20081126/#NT-doctypedecl.
*/
DoubleDocumentTypeDeclaration,
/**
@brief Check http://www.w3.org/TR/2009/REC-xml-names-20091208/#NT-QName.
*/
InvalidTagName,
/**
@brief Check http://www.w3.org/TR/2009/REC-xml-names-20091208/#NT-QName.
*/
InvalidAttributeName,
/**
@brief For example: <tt><tagname attr[end of document]</tt>.
*/
UnclosedToken,
/**
@brief Invalid syntax of the Reference.
Check http://www.w3.org/TR/2008/REC-xml-20081126/#NT-Reference.
*/
InvalidReferenceSyntax,
/**
@brief Code point in the character reference doesn't match
the valid character in ISO/IEC 10646 character set.
Check http://www.w3.org/TR/2008/REC-xml-20081126/#NT-CharRef.
*/
InvalidCharacterReference,
/**
@brief For example: <tt><a>text</b></tt>. <tt></a></tt> expected, but <tt></b></tt> found.
Another example: <tt></b></tt>. Found closing tag, but there is no start tag of @c b.
Both examples are not allowed in the XML files.
*/
UnexpectedEndTag,
/**
@brief For example: <tt><a><b><c></c></b></tt>. Unclosed @c a tag.
*/
UnclosedTag,
/**
@brief There is no root element in a document.
*/
NoElement,
/**
@brief More than one attribute name in the same start-tag or empty-element tag.
*/
DoubleAttributeName,
/**
@brief There is some name prefix which is not bound to any namespace URI.
*/
PrefixWithoutAssignedNamespace,
/**
@brief Namespace declaration with a prefix cannot have an empty value.
*/
PrefixWithEmptyNamespace,
/**
@brief Reserved xmlns prefix cannot be declared or set to an empty value.
*/
XmlnsDeclared,
/**
@brief Prefix is bound to the reserved namespace.
*/
PrefixBoundToReservedNamespace,
/**
@brief Reserved namespace cannot be declared as a default namespace.
*/
ReservedNamespaceAsDefault,
/**
@brief Prefix 'xml' is reserved for use by the XML and has a fixed
namespace URI http://www.w3.org/XML/1998/namespace.
*/
InvalidXmlPrefixDeclaration
};
/**
@brief Delimiter for an attribute value.
*/
enum class QuotationMark
{
/**
@brief Attribute is delimited by a single-quote characters (for example <tt><a name='value'></tt> ).
*/
SingleQuote,
/**
@brief Attribute is delimited by a double-quote characters (for example <tt><a name="value"></tt> ).
*/
DoubleQuote
};
/**
@brief Class for storing attribute data like name and value.
*/
template <typename TStringType>
class InspectedAttribute
{
public:
/**
@brief Alias to the string type provided by the class template parameter.
*/
typedef TStringType StringType;
/**
@brief Unsigned integer type definition for determining location in the XML document.
This type should be enough to store any file size or memory buffer size.
*/
typedef std::uint_least64_t SizeType;
/**
@brief Qualified name of the attribute.
*/
StringType Name;
/**
@brief Value of the attribute.
*/
StringType Value;
/**
@brief Local name of the attribute.
*/
StringType LocalName;
/**
@brief Namespace prefix of the attribute.
*/
StringType Prefix;
/**
@brief Namespace URI of the attribute.
*/
StringType NamespaceUri;
/**
@brief Row number of the attribute name.
Starting value is 1. For example:
@verbatim
<root>
<a
attrName=
"value"
/>
</root>
@endverbatim
Row number of @c attrName is 3.
@sa Column.
*/
SizeType Row;
/**
@brief Column number of the attribute name.
Starting value is 1. For example:
@verbatim
<root attrName="value"/>
@endverbatim
Column number of @c attrName is 7.
@warning Carriage return characters (U+000D) are ignored.
@sa Row.
*/
SizeType Column;
/**
@brief Delimiter of the attribute value.
*/
QuotationMark Delimiter;
};
/// @cond DETAILS
namespace Details
{
enum class Bom
{
None,
StreamError,
Invalid,
Utf8,
Utf16BE,
Utf16LE,
Utf32BE,
Utf32LE
};
Bom ReadBom(std::istream* inputStream);
template <typename TInputIterator>
Bom ReadBom(TInputIterator& first, TInputIterator& last);
template <
typename TInputIterator,
typename TCharacterType,
typename TTraits = std::char_traits<TCharacterType> >
class BasicIteratorsBuf
: public std::basic_streambuf<TCharacterType, TTraits>
{
public:
typedef TInputIterator IteratorType;
typedef std::basic_streambuf<TCharacterType, TTraits> StreambufType;
typedef TCharacterType char_type;
typedef TTraits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
protected:
IteratorType curIter;
IteratorType endIter;
virtual int_type underflow();
virtual int_type uflow();
virtual std::streamsize showmanyc();
public:
BasicIteratorsBuf(IteratorType first, IteratorType last)
: StreambufType(), curIter(first), endIter(last)
{
}
virtual ~BasicIteratorsBuf()
{
}
};
template <typename TStringType>
class NamespaceDeclaration
{
public:
typedef TStringType StringType;
typedef std::uint_least64_t SizeType;
StringType Prefix;
StringType Uri;
SizeType TagIndex; // Counting from 0.
};
template <typename TStringType>
class UnclosedTag
{
public:
typedef TStringType StringType;
typedef std::uint_least64_t SizeType;
StringType Name;
StringType LocalName;
StringType Prefix;
StringType NamespaceUri;
SizeType Row;
SizeType Column;
};
}
/// @endcond
/**
@brief Streaming XML parser class.
Example:
@code{.cpp}
#include "XmlInspector.hpp"
#include <iostream>
#include <cstdlib>
int main()
{
Xml::Inspector<Xml::Encoding::Utf8Writer> inspector("test.xml");
while (inspector.Inspect())
{
switch (inspector.GetInspected())
{
case Xml::Inspected::StartTag:
std::cout << "[StartTag] name(" << inspector.GetName() <<
"), value(" << inspector.GetValue() << ").\n";
break;
case Xml::Inspected::EndTag:
std::cout << "[EndTag] name(" << inspector.GetName() <<
"), value(" << inspector.GetValue() << ").\n";
break;
case Xml::Inspected::EmptyElementTag:
std::cout << "[EmptyElementTag] name(" << inspector.GetName() <<
"), value(" << inspector.GetValue() << ").\n";
break;
case Xml::Inspected::Text:
std::cout << "[Text] value(" << inspector.GetValue() << ").";
break;
case Xml::Inspected::Whitespace:
// Ignore white spaces between markup.
break;
default:
std::cout << "[...] name(" << inspector.GetName() <<
"), value(" << inspector.GetValue() << ").\n";
break;
}
}
if (inspector.GetErrorCode() != Xml::ErrorCode::None)
{
std::cout << "Error: " << inspector.GetErrorMessage() <<
" At row: " << inspector.GetRow() <<
", column: " << inspector.GetColumn() << "\n";
}
return EXIT_SUCCESS;
}
@endcode
@tparam TCharactersWriter Writer with a specified encoding. You don't need to care how the XML file is encoded.
You can choose how you want to store the strings between Xml::Encoding::Utf8Writer, Xml::Encoding::Utf16Writer
and Xml::Encoding::Utf32Writer class from CharactersWriter.hpp file. They respectively store the strings in
@c std::string, @c std::u16string and @c std::u32string. You can also write your own fancy way of
storing strings. For example you may want to use @c std::wstring and even other than Unicode encoding.
*/
template <typename TCharactersWriter>
class Inspector
{
public:
/**
@brief Alias of the characters writer type that is used to write strings.
*/
typedef TCharactersWriter CharactersWriterType;
/**
@brief String type provided by the CharactersWriterType.
*/
typedef typename TCharactersWriter::StringType StringType;
/**
@brief Attribute type.
*/
typedef InspectedAttribute<StringType> AttributeType;
/**
@brief Unsigned integer type definition for determining location in the XML document.
This type should be enough to store any file size or memory buffer size.
*/
typedef std::uint_least64_t SizeType;
private:
typedef typename StringType::size_type StringSizeType;
typedef Details::UnclosedTag<StringType> UnclosedTagType;
typedef Details::NamespaceDeclaration<StringType> NamespaceDeclarationType;
typedef typename std::deque<AttributeType>::size_type AttributesSizeType;
typedef typename std::deque<UnclosedTagType>::size_type UnclosedTagsSizeType;
typedef typename std::deque<NamespaceDeclarationType>::size_type NamespacesSizeType;
static const unsigned char Space = 0x20; // ' '
static const unsigned char LineFeed = 0x0A; // '\n'
static const unsigned char CarriageReturn = 0x0D; // '\r'
static const unsigned char LessThan = 0x3C; // '<'
static const unsigned char GreaterThan = 0x3E; // '>'
static const unsigned char Equals = 0x3D; // '='
static const unsigned char SingleQuote = 0x27; // '\''
static const unsigned char DoubleQuote = 0x22; // '\"'
static const unsigned char Slash = 0x2F; // '/'
static const unsigned char Question = 0x3F; // '?'
static const unsigned char Exclamation = 0x21; // '!'
static const unsigned char Minus = 0x2D; // '-'
static const unsigned char Ampersand = 0x26; // '&'
static const unsigned char Hash = 0x23; // '#'
static const unsigned char X = 0x78; // 'x'
static const unsigned char Colon = 0x3A; // ':'
static const unsigned char Semicolon = 0x3B; // ';'
static const unsigned char LeftSquareBracket = 0x5B; // '['
static const unsigned char RightSquareBracket = 0x5D; // ']'
static const unsigned char Dot = 0x2E; // '.'
static const unsigned char LowerXml[3]; // "xml"
static const unsigned char UpperXml[3]; // "XML"
static const unsigned char Xmlns[5]; // "xmlns"
static const unsigned char XmlUri[36]; // "http://www.w3.org/XML/1998/namespace"
static const unsigned char XmlnsUri[29]; // "http://www.w3.org/2000/xmlns/"
static const unsigned char XmlDeclarationVersion[7]; // "version"
static const unsigned char XmlDeclarationEncoding[8]; // "encoding"
static const unsigned char XmlDeclarationStandalone[10]; // "standalone"
static const unsigned char Yes[3]; // "yes"
static const unsigned char No[2]; // "no"
static const unsigned char CDATA[5]; // "CDATA"
static const unsigned char DOCTYPE[7]; // "DOCTYPE"
static const unsigned char LtEntityName[2]; // "lt"
static const unsigned char GtEntityName[2]; // "gt"
static const unsigned char AmpEntityName[3]; // "amp"
static const unsigned char AposEntityName[4]; // "apos"
static const unsigned char QuotEntityName[4]; // "quot"
// Use only for 1-byte characters!
static const unsigned char ToLower[256];
// Source types.
static const int SourceNone = 0; // Inspector() constructor.
static const int SourcePath = 1; // Inspector(const char*) or Inspector(const std::string&) constructor.
static const int SourceStream = 2; // Inspector(std::istream*) constructor.
static const int SourceIterators = 3; // Inspector(InputIterator first, InputIterator last) constructor.
static const int SourceReader = 4; // Inspector(Encoding::CharactersReader*) constructor.
static const StringSizeType NameReserve = 31;
static const StringSizeType ValueReserve = 63;
static const StringSizeType LocalNameReserve = 15;
static const StringSizeType PrefixReserve = 15;
static const StringSizeType NamespaceUriReserve = 63;
SizeType row;
SizeType column;
SizeType currentRow;
SizeType currentColumn;
Inspected node;
ErrorCode err;
const char* errMsg;
std::string fPath;
std::ifstream fileStream;
std::istream* inputStreamPtr;
Encoding::CharactersReader* reader;
int sourceType;
bool afterBom;
Details::Bom bom;
StringType name;
StringType value;
StringType localName;
StringType prefix;
StringType namespaceUri;
StringType entityName;
std::u32string comparingName;
SizeType entityNameCharCount;
char32_t currentCharacter;
char32_t bufferedCharacter;
bool foundElement;
bool foundDOCTYPE;
bool eof;
StringType lowerXmlString;
StringType xmlnsString;
StringType xmlUriString;
StringType xmlnsUriString;
// Instead of removing objects from collection I decrement size.
// It's a fake size, but I don't want to
// allocate strings in objects after each element node and each XML document.
// To clear these collections you can call Inspector::Clear method.
std::deque<AttributeType> attributes;
AttributesSizeType attributesSize;
std::deque<UnclosedTagType> unclosedTags;
UnclosedTagsSizeType unclosedTagsSize;
std::deque<NamespaceDeclarationType> namespaces;
NamespacesSizeType namespacesSize;
// We don't need to check carriage return
// while NextCharBad method removes them for us.
// That's why I use this method instead of
// Xml::Encoding::CharactersReader::IsWhiteSpace.
static bool IsWhiteSpace(char32_t codePoint);
void SetError(ErrorCode errorCode);
void SavePosition();
// Extracts the next character and sets the error flag
// if eof (only if insideTag flag), invalid character or stream error.
// Returns true if error or eof (insideTag == false) happened.
bool NextCharBad(bool insideTag);
void ParseBom();
bool ParseElement();
bool ParseAttributes();
bool ParseEndTag();
bool ParseText();
bool ParseQuestion();
bool ParseXmlDeclaration();
bool ParseProcessingInstruction();
bool ParseExclamation();
bool ParseComment();
bool ParseCDATA();
bool ParseDOCTYPE();
void PrepareNode();
bool NamespacesStuff();
// Returns false if error.
bool ParseCharacterReference(char32_t& result, bool insideTag);
// Returns 1 if predefined entity, 0 if unknown entity, -1 if error.
int ParseEntityReference(bool insideTag);
bool AttributeUniqueness();
bool ResolveEncoding(const AttributeType& encoding);
bool IsUtf8Charset();
bool IsUtf16Charset();
bool IsUtf16BECharset();
bool IsUtf16LECharset();
bool IsUtf32Charset();
bool IsUtf32BECharset();
bool IsUtf32LECharset();
bool IsISO_8859_1_Charset();
bool IsISO_8859_2_Charset();
bool IsISO_8859_3_Charset();
bool IsISO_8859_4_Charset();
bool IsISO_8859_5_Charset();
bool IsISO_8859_6_Charset();
bool IsISO_8859_7_Charset();
bool IsISO_8859_8_Charset();
bool IsISO_8859_9_Charset();
bool IsISO_8859_10_Charset();
bool IsISO_8859_13_Charset();
bool IsISO_8859_14_Charset();
bool IsISO_8859_15_Charset();
bool IsISO_8859_16_Charset();
bool IsTIS620Charset();
bool IsWindows874Charset();
bool IsWindows1250Charset();
bool IsWindows1251Charset();
bool IsWindows1252Charset();
bool IsWindows1253Charset();
bool IsWindows1254Charset();
bool IsWindows1255Charset();
bool IsWindows1256Charset();
bool IsWindows1257Charset();
bool IsWindows1258Charset();
AttributeType& NewAttribute();
UnclosedTagType& NewUnclosedTag();
NamespaceDeclarationType& NewNamespace();
bool CharsetEqual(const char32_t* charset);
bool CharsetEqual(const unsigned char* charset, std::size_t len);
void InitStrings();
// Copy constructor is inaccessible for this class.
Inspector(const Inspector&) { };
// Assignment operator is inaccessible for this class.
Inspector& operator=(const Inspector&) { return *this; };
public:
/**
@brief Initializes a new instance of the Inspector class.
*/
Inspector();
/**
@brief Initializes a new instance of the Inspector class
with the specified file path.
*/
Inspector(const char* filePath);
/**
@brief Initializes a new instance of the Inspector class
with the specified file path.
*/
Inspector(const std::string& filePath);
/**
@brief Initializes a new instance of the Inspector class
with the specified stream.
*/
Inspector(std::istream* inputStream);
/**
@brief Initializes a new instance of the Inspector class
with the specified iterators.
@param first,last Input iterators to the initial
and final positions in a sequence of bytes. The range used
is [first,last), which contains all the bytes
between first and last, including the byte pointed
by first but not the byte pointed by last.
*/
template <typename TInputIterator>
Inspector(TInputIterator first, TInputIterator last);
/**
@brief Initializes a new instance of the Inspector class
with the specified characters reader interface.
*/
Inspector(Encoding::CharactersReader* reader);
/**
@brief Destructor.
*/
~Inspector();
/**
@brief Inspects the next node from the stream.
@return True if the next node was inspected successfully.
False if there are no more nodes to inspect.
*/
bool Inspect();
/**
@brief Gets the last inspected node.
*/
Inspected GetInspected() const;
/**
@brief Gets the qualified name of the last inspected node.
*/
const StringType& GetName() const;
/**
@brief Gets the value of the last inspected node.
*/
const StringType& GetValue() const;
/**
@brief Gets the local name of the last inspected node.
*/
const StringType& GetLocalName() const;
/**
@brief Gets the namespace prefix of the last inspected node.
*/
const StringType& GetPrefix() const;
/**
@brief Gets the namespace URI of the last inspected node.
*/
const StringType& GetNamespaceUri() const;
/**
@brief Gets a value indicating whether the last inspected node has any attributes.
*/
bool HasAttributes() const;
/**
@brief Gets the number of attributes on the last inspected node.
*/
SizeType GetAttributesCount() const;
/**
@brief Returns attribute at the specified index on the last inspected node.
@param index Index of the attribute.
@return Constant reference to the chosen attribute.
@exception std::out_of_range Index starting value is 0,
and GetAttributesCount() result should be greater than index.
*/
const AttributeType& GetAttributeAt(SizeType index) const;
/**
@brief Gets the last error message.
*/
const char* GetErrorMessage() const;
/**
@brief Gets the last error code.
*/
ErrorCode GetErrorCode() const;
/**
@brief Gets the current row number.
Starting value is 1. For example:
@verbatim
<root>
<a>aaa</a>
<b>
bbb
</b>
</root>
@endverbatim
Row number of @c bbb is 4.
@sa GetColumn() and GetDepth().
*/
SizeType GetRow() const;
/**
@brief Gets the current column number.
Starting value is 1. For example:
@verbatim
<root>
abcdef<mytag />
</root>
@endverbatim
Column number of <tt><mytag /></tt> is 7.
@sa GetRow() and GetDepth().
*/
SizeType GetColumn() const;
/**
@brief Gets the depth of the last inspected node in the XML document.
Example:
@verbatim
<root>
<a>aaa</a>
<b>
bbb
</b>
</root>
@endverbatim
Depth of @c aaa is 2, the same as depth of @c bbb.
Depht of <@c a> tag, the same as closing tag </@c a> is 1.
@sa GetRow() and GetColumn().
*/
SizeType GetDepth() const;
/**
@brief Removes the association with the source and resets
the state of Inspector object.
It doesn't clear the helpful containers to reduce the number of
string allocations in future reading nodes. To completely
clear those containers you should call the Clear method instead.
@sa Clear().
*/
void Reset();
/**
@brief Resets the state of Inspector object and assign
the source to the specified file path.
It doesn't clear the helpful containers to reduce the number of
string allocations in future reading nodes. To completely
clear those containers you can call the Clear method.
@sa Clear().
*/
void Reset(const char* filePath);
/**
@brief Resets the state of Inspector object and assign
the source to the specified file path.
It doesn't clear the helpful containers to reduce the number of
string allocations in future reading nodes. To completely
clear those containers you can call the Clear method.
@sa Clear().
*/
void Reset(const std::string& filePath);
/**
@brief Resets the state of Inspector object and assign
the source to the specified stream.
It doesn't clear the helpful containers to reduce the number of
string allocations in future reading nodes. To completely
clear those containers you can call the Clear method.
@sa Clear().
*/
void Reset(std::istream* inputStream);
/**
@brief Resets the state of Inspector object and assign
the source to the specified byte sequence.
@param first,last Input iterators to the initial
and final positions in a sequence of bytes. The range used
is [first,last), which contains all the bytes
between first and last, including the element pointed
by first but not the element pointed by last.
It doesn't clear the helpful containers to reduce the number of
string allocations in future reading nodes. To completely
clear those containers you can call the Clear method.