-
Notifications
You must be signed in to change notification settings - Fork 17
/
yatexml.h
2588 lines (2276 loc) · 76.5 KB
/
yatexml.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
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
/**
* yatexml.h
* This file is part of the YATE Project http://YATE.null.ro
*
* XML Parser and support classes
*
* Yet Another Telephony Engine - a fully featured software PBX and IVR
* Copyright (C) 2004-2023 Null Team
*
* This software is distributed under multiple licenses;
* see the COPYING file in the main directory for licensing
* information for this specific distribution.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
*
* 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.
*/
#ifndef __YATEXML_H
#define __YATEXML_H
#ifndef __cplusplus
#error C++ is required
#endif
#include <yateclass.h>
/**
* Holds all Telephony Engine related classes.
*/
namespace TelEngine {
class XmlSaxParser;
class XmlDomParser;
class XmlDeclaration;
class XmlFragment;
class XmlChild;
class XmlParent;
class XmlDocument;
class XmlElement;
class XmlComment;
class XmlCData;
class XmlText;
class XmlDoctype;
class XPath;
struct YATE_API XmlEscape {
/**
* Value to match
*/
const char* value;
/**
* Character replacement for value
*/
char replace;
};
/**
* A Serial Access Parser (SAX) for arbitrary XML data
* @short Serial Access XML Parser
*/
class YATE_API XmlSaxParser : public DebugEnabler
{
public:
enum Error {
NoError = 0,
NotWellFormed,
Unknown,
IOError,
ElementParse,
ReadElementName,
InvalidElementName,
ReadingAttributes,
CommentParse,
DeclarationParse,
DefinitionParse,
CDataParse,
ReadingEndTag,
Incomplete,
InvalidEncoding,
UnsupportedEncoding,
UnsupportedVersion,
// Errors set by XmlDomParser::getXml()
GetXmlMissing,
GetXmlEmpty,
};
enum Type {
None = 0,
Text = 1,
CData = 2,
Element = 3,
Doctype = 4,
Comment = 5,
Declaration = 6,
Instruction = 7,
EndTag = 8,
Special = 9
};
/**
* Destructor
*/
virtual ~XmlSaxParser();
/**
* Get the number of bytes successfully parsed
* @return The number of bytes successfully parsed
*/
inline unsigned int offset() const
{ return m_offset; }
/**
* Get the row where the parser has found an error
* @return The row number
*/
inline unsigned int row() const
{ return m_row; }
/**
* Get the column where the parser has found an error
* @return The column number
*/
inline unsigned int column() const
{ return m_column; }
/**
* Retrieve the parser's buffer
* @return The parser's buffer
*/
inline const String& buffer() const
{ return m_buf; }
/**
* Parse a given string
* @param data The data to parse
* @return True if all data was successfully parsed
*/
bool parse(const char* data);
/**
* Process incomplete text if the parser is completed.
* This method should be called to complete text after
* all data was pushed into the parser
* @return True if all data was successfully parsed
*/
bool completeText();
/**
* Get the error code found while parsing
* @return Error code
*/
inline Error error()
{ return m_error; }
/**
* Set the error code and destroys a child if error code is not NoError
* @param error The error found
* @param child Child to destroy
* @return False on error
*/
bool setError(Error error, XmlChild* child = 0);
/**
* Retrieve the error string associated with current error status
* @param defVal Value to return if not found
* @return The error string
*/
inline const char* getError(const char* defVal = "Xml error")
{ return getError(m_error,defVal); }
/**
* @return The last xml type that we were parsing, but we have not finished
*/
inline Type unparsed()
{ return m_unparsed; }
/**
* Set the last xml type that we were parsing, but we have not finished
* @param id The xml type that we haven't finish to parse
*/
inline void setUnparsed(Type id)
{ m_unparsed = id;}
/**
* Reset error flag
*/
virtual void reset();
/**
* @return The internal buffer
*/
const String& getBuffer() const
{ return m_buf; }
/**
* Retrieve the error string associated with a given error code
* @param code Code of the error to look up
* @param defVal Value to return if not found
* @return The error string
*/
static inline const char* getError(int code, const char* defVal = "Xml error")
{ return lookup(code,s_errorString,defVal); }
/**
* Check if the given character is blank
* @param c The character to verify
* @return True if c is blank
*/
static inline bool blank(char c)
{ return (c <= 0x20) && ((c == 0x20) || (c == 0x09) || (c == 0x0d) || (c == 0x0a)); }
/**
* Verify if the given character is in the range allowed
* to be first character from a xml tag
* @param ch The character to check
* @return True if the character is in range
*/
static inline bool checkFirstNameCharacter(unsigned char ch) {
return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')
|| (ch == ':') || (ch == '_')
|| (ch >= 0xc0 && ch <= 0xd6) || (ch >= 0xd8 && ch <= 0xf6) || (ch >= 0xf8);
}
/**
* Check if the given character is in the range allowed for an xml char
* @param c The character to check
* @return True if the character is in range
*/
static bool checkDataChar(unsigned char c);
/**
* Verify if the given character is in the range allowed for a xml name
* @param ch The character to check
* @return True if the character is in range
*/
static inline bool checkNameCharacter(unsigned char ch) {
return checkFirstNameCharacter(ch) || ch == '-' || ch == '.' || (ch >= '0' && ch <= '9')
|| ch == 0xB7;
}
/**
* Check if a given string is a valid xml tag name
* @param buf The string to check
* @return True if the string is a valid xml tag name
*/
static bool validTag(const String& buf);
/**
* XmlEscape the given text
* @param buf Destination buffer
* @param text The text to escape
* @return Destination buffer reference
*/
static String& escape(String& buf, const String& text);
/**
* Unescape the given text.
* Handled: &lt; &gt; &apos; &quot; &amp;
* &\#DecimalNumber; &\#xHexNumber;
* @param text The requested text to unescape
* @param error Destination for error string
* @param found Optional flag to be set if unescape was found
* @return True on success, false otherwise
*/
static inline bool unEscape(String& text, String* error, bool* found = 0)
{ return unEscape(text,text.c_str(),text.length(),error,false,found); }
/**
* Unescape the given text.
* Handled: &lt; &gt; &apos; &quot; &amp;
* &\#DecimalNumber; &\#xHexNumber;
* @param text The requested text to unescape
* @param str Input buffer
* @param len Input buffer length
* @param inText Use destination text during unescape.
* If enabled the destination text may be incomplete on failure.
* The method will use a temporary buffer if disabled
* This parameter is ignored and handled as 'false' if 'str' points to destination string's buffer
* @param error Destination for error string
* @param found Optional flag to be set if unescape was found
* @return True on success, false otherwise
*/
static bool unEscape(String& text, const char* str, unsigned int len, String* error,
bool inText = false, bool* found = 0);
/**
* Errors dictionary
*/
static const TokenDict s_errorString[];
/**
* Escaped strings dictionary
*/
static const XmlEscape s_escape[];
protected:
/**
* Constructor
* @param name Debug name
*/
XmlSaxParser(const char* name = "XmlSaxParser");
/**
* Parse an instruction form the main buffer.
* Extracts the parsed string from buffer if returns true
* @return True if the instruction was parsed successfully
*/
bool parseInstruction();
/**
* Parse a CData section form the main buffer.
* Extracts the parsed string from buffer if returns true
* @return True if the CData section was parsed successfully
*/
bool parseCData();
/**
* Parse a comment form the main buffer.
* Extracts the parsed string from buffer if returns true
* @return True if the comment was parsed successfully
*/
bool parseComment();
/**
* Parse an element form the main buffer.
* Extracts the parsed string from buffer if returns true
* @return True if the element was parsed successfully
*/
bool parseElement();
/**
* Parse a declaration form the main buffer.
* Extracts the parsed string from buffer if returns true
* @return True if the declaration was parsed successfully
*/
bool parseDeclaration();
/**
* Helper method to classify the Xml objects starting with "<!" sequence.
* Extracts the parsed string from buffer if returns true
* @return True if a corresponding xml object was found and parsed successfully
*/
bool parseSpecial();
/**
* Parse an endtag form the main buffer.
* Extracts the parsed string from buffer if returns true
* @return True if the endtag was parsed successfully
*/
bool parseEndTag();
/**
* Parse a doctype form the main buffer.
* Extracts the parsed string from buffer if returns true.
* Warning: This is a stub implementation
* @return True if the doctype was parsed successfully
*/
bool parseDoctype();
/**
* Parse an unfinished xml object.
* Extracts the parsed string from buffer if returns true
* @return True if the object was parsed successfully
*/
bool auxParse();
/**
* Unescape the given text.
* Handled: &lt; &gt; &apos; &quot; &amp;
* &\#DecimalNumber; &\#xHexNumber;
* @param text The requested text to unescape
*/
void unEscape(String& text);
/**
* Remove blank characters from the begining of the buffer
*/
void skipBlanks();
/**
* Check if a character is an angle bracket
* @param c The character to verify
* @return True if c is an angle bracket
*/
inline bool badCharacter(char c)
{ return c == '<' || c == '>'; }
/**
* Reset the error
*/
inline void resetError()
{ m_error = NoError; }
/**
* Reset parsed value and parameters
*/
inline void resetParsed()
{ m_parsed.clear(); m_parsed.clearParams(); }
/**
* Extract the name of an element or instruction
* @return The extracted string or 0
*/
String* extractName(bool& empty);
/**
* Extract an attribute
* @return The attribute value or 0
*/
NamedString* getAttribute();
/**
* Callback method. Is called when a comment was successfully parsed.
* Default implementation does nothing
* @param text The comment content
*/
virtual void gotComment(const String& text)
{ }
/**
* Callback method. Is called when an instruction was successfully parsed.
* Default implementation does nothing
* @param instr The instruction content
*/
virtual void gotProcessing(const NamedString& instr)
{ }
/**
* Callback method. Is called when a declaration was successfully parsed.
* Default implementation does nothing
* @param decl The declaration content
*/
virtual void gotDeclaration(const NamedList& decl)
{ }
/**
* Callback method. Is called when a text was successfully parsed.
* Default implementation does nothing
* @param text The text content
*/
virtual void gotText(const String& text)
{ }
/**
* Callback method. Is called when a CData section was successfully parsed.
* Default implementation does nothing
* @param data The CData content
*/
virtual void gotCdata(const String& data)
{ }
/**
* Callback method. Is called when an element was successfully parsed.
* Default implementation does nothing
* @param element The element content
* @param empty True if the element does not have attributes
*/
virtual void gotElement(const NamedList& element, bool empty)
{ }
/**
* Callback method. Is called when a end tag was successfully parsed.
* Default implementation does nothing
* @param name The end tag name
*/
virtual void endElement(const String& name)
{ }
/**
* Callback method. Is called when a doctype was successfully parsed.
* Default implementation does nothing
* @param doc The doctype content
*/
virtual void gotDoctype(const String& doc)
{ }
/**
* Callback method. Is called to check if we have an incomplete element.
* Default implementation returns always true
* @return True
*/
virtual bool completed()
{ return true; }
/**
* Calls gotElement() and eset parsed on success
* @param list The list element and its attributes
* @param empty True if the element does not have attributes
* @return True if there is no error
*/
bool processElement(NamedList& list, bool empty);
/**
* Unescape text, call gotText() and reset parsed on success
* @param text The text to process
* @return True if there is no error
*/
bool processText(String& text);
/**
* The offset where the parser was stop
*/
unsigned int m_offset;
/**
* The row where the parser was stop
*/
unsigned int m_row;
/**
* The column where the parser was stop
*/
unsigned int m_column;
/**
* The error code found while parsing data
*/
Error m_error;
/**
* The main buffer
*/
String m_buf;
/**
* The parser data holder.
* Keeps the parsed data when an incomplete xml object is found
*/
NamedList m_parsed;
/**
* The last parsed xml object code
*/
Type m_unparsed;
};
/**
* Xml Parent for a Xml child
* @short Xml Parent
*/
class YATE_API XmlParent
{
public:
/**
* Constructor
*/
XmlParent()
{ }
/**
* Destructor
*/
virtual ~XmlParent()
{ }
/**
* Get an XmlDocument object from this XmlParent.
* Default implementation return 0
* @return 0
*/
virtual XmlDocument* document()
{ return 0; }
/**
* Get an XmlFragment object from this XmlParent.
* Default implementation return 0
* @return 0
*/
virtual XmlFragment* fragment()
{ return 0; }
/**
* Get an XmlElement object from this XmlParent.
* Default implementation return 0
* @return 0
*/
virtual XmlElement* element()
{ return 0; }
/**
* Append a new child to this XmlParent
* @param child The child to append
* @return NoError if the child was successfully added
*/
virtual XmlSaxParser::Error addChild(XmlChild* child) = 0;
/**
* Append a new child of this XmlParent, release the object on failure
* @param child The child to append
* @param code Optional pointr to error code to be filled on failure
* @return The child on success, 0 on failure
*/
inline XmlChild* addChildSafe(XmlChild* child, XmlSaxParser::Error* code = 0) {
XmlSaxParser::Error err = addChild(child);
if (err != XmlSaxParser::NoError) {
TelEngine::destruct(child);
if (code)
*code = err;
}
return child;
}
/**
* Remove a child
* @param child The child to remove
* @param delObj True to delete the object
* @return XmlChild pointer if found and not deleted
*/
virtual XmlChild* removeChild(XmlChild* child, bool delObj = true) = 0;
/**
* Reset this xml parent.
* Default implementation does nothing
*/
virtual void reset()
{ }
/**
* Obtain this xml parent children.
* Default implementation returns an empty list
* @return The list of children
*/
virtual const ObjList& getChildren() const
{ return ObjList::empty(); }
/**
* Clear this xml parent children.
* Default implementation does nothing
*/
virtual void clearChildren()
{ }
/**
* Check if at least one child element exists
* @return True if this parent has at least one child
*/
inline bool hasChildren() const
{ return getChildren().skipNull() != 0; }
};
/**
* A Document Object Model (DOM) parser for XML documents and fragments
* @short Document Object Model XML Parser
*/
class YATE_API XmlDomParser : public XmlSaxParser
{
friend class XmlChild;
public:
/**
* XmlDomParser constructor
* @param name Debug name
* @param fragment True if this parser needs to parse a piece of a xml document
*/
XmlDomParser(const char* name = "XmlDomParser", bool fragment = false);
/**
* XmlDomParser constructor
* @param fragment The fragment who should keep the parsed data
* @param takeOwnership True to take ownership of the fragment
*/
XmlDomParser(XmlParent* fragment, bool takeOwnership);
/**
* Destructor
*/
virtual ~XmlDomParser();
/**
* Obtain an XmlDocument from the parsed data
* @return The XmlDocument or 0
*/
XmlDocument* document()
{ return m_data->document(); }
/**
* Obtain an XmlFragment from the parsed data
* @return The XmlFragment or 0
*/
XmlFragment* fragment()
{ return m_data->fragment(); }
/**
* Reset parser
*/
virtual void reset();
/**
* Check if the current element is the given one
* @param el The element to compare with
* @return True if they are equal
*/
inline bool isCurrent(const XmlElement* el) const
{ return el == m_current; }
/**
* Retrieve an XML element from list parameter
* @param params Parameters list
* @param param Parameter name. Defaults to 'xml' if empty
* @param npOwner Optional pointer to data to be filled with NamedPointer owning the element.
* If parameter is NamedPointer carrying an XmlElement and 'npOwner' is NULL the pointer will
* be taken from it
* @param error Optional pointer to parser error code
* @param parserName Optional parser name if needing to parse from string
* @param dbg Optional DebugEnabler to chain temporary parser and use for failure warning
* @param warnLevel Put a parse failure debug level (if at least 1).
* This parameter is ignored if 'dbg' is NULL
* @return XmlElement pointer, NULL if missing or parser failure.
* If 'npOwner' is given and set on return the returned pointer is owned by it.
* If 'npOwner' is not given or not set on return the returned pointer is owned by the caller.
*/
static XmlElement* getXml(const NamedList& params, const String& param, NamedPointer** npOwner,
int* error = 0, const char* parserName = 0, DebugEnabler* dbg = 0,
int warnLevel = DebugMild);
/**
* Retrieve an XML element from list parameter
* @param params Parameters list
* @param param Parameter name. Defaults to 'xml' if empty
* @param autoDel Owner of returned xml if any. It will own the xml element if we built one
* @param error Optional pointer to parser error code
* @param parserName Optional parser name if needing to parse from string
* @param dbg Optional DebugEnabler to chain temporary parser and use for failure warning
* @param warnLevel Put a parse failure debug level (if at least 1).
* This parameter is ignored if 'dbg' is NULL
* @return XmlElement pointer, NULL if missing or parser failure.
*/
static inline XmlElement* getXml(const NamedList& params, const String& param, AutoGenObject& autoDel,
int* error = 0, const char* parserName = 0, DebugEnabler* dbg = 0,
int warnLevel = DebugMild) {
NamedPointer* np = 0;
XmlElement* xml = getXml(params,param,&np,error,parserName,dbg,warnLevel);
autoDel.set(np ? 0 : (GenObject*)xml);
return xml;
}
protected:
/**
* Append a xml comment in the xml tree
* @param text The comment content
*/
virtual void gotComment(const String& text);
/**
* Append a xml instruction in the xml tree
* @param instr The instruction content
*/
virtual void gotProcessing(const NamedString& instr);
/**
* Append a xml declaration in the xml tree
* @param decl The declaration content
*/
virtual void gotDeclaration(const NamedList& decl);
/**
* Append a xml text in the xml tree
* @param text The text content
*/
virtual void gotText(const String& text);
/**
* Append a xml CData in the xml tree
* @param data The CData content
*/
virtual void gotCdata(const String& data);
/**
* Append a xml element in the xml tree
* @param element The element content
* @param empty True if the element does not have attributes
*/
virtual void gotElement(const NamedList& element, bool empty);
/**
* Complete current element
* @param name The end tag name
*/
virtual void endElement(const String& name);
/**
* Append a xml doctype in the xml tree
* @param doc The doctype content
*/
virtual void gotDoctype(const String& doc);
/**
* Callback method. Is called to check if we have an incomplete element
* @return True if current element is not 0
*/
virtual bool completed()
{ return m_current == 0; }
private:
XmlElement* m_current; // The current xml element
XmlParent* m_data; // Main xml fragment
bool m_ownData; // The DOM owns data
};
/**
* Xml Child for Xml document
* @short Xml Child
*/
class YATE_API XmlChild : public GenObject
{
YCLASS(XmlChild,GenObject)
friend class XmlDomParser;
public:
/**
* Constructor
*/
XmlChild();
/**
* Set this child's parent
* @param parent Parent of this child
*/
virtual void setParent(XmlParent* parent)
{ }
/**
* Get a Xml element
* @return 0
*/
virtual XmlElement* xmlElement()
{ return 0; }
/**
* Get a Xml comment
* @return 0
*/
virtual XmlComment* xmlComment()
{ return 0; }
/**
* Get a Xml CData
* @return 0
*/
virtual XmlCData* xmlCData()
{ return 0; }
/**
* Get a Xml text
* @return 0
*/
virtual XmlText* xmlText()
{ return 0; }
/**
* Get a Xml declaration
* @return 0
*/
virtual XmlDeclaration* xmlDeclaration()
{ return 0; }
/**
* Get a Xml doctype
* @return 0
*/
virtual XmlDoctype* xmlDoctype()
{ return 0; }
/**
* Replaces all ${paramname} with the corresponding parameters
* @param params List of parameters
*/
virtual void replaceParams(const NamedList& params)
{}
};
/**
* Xml Declaration for Xml document
* @short Xml Declaration
*/
class YATE_API XmlDeclaration : public XmlChild
{
YCLASS(XmlDeclaration,XmlChild)
public:
/**
* Constructor
* @param version XML version attribute
* @param enc Encoding attribute
*/
XmlDeclaration(const char* version = "1.0", const char* enc = "utf-8");
/**
* Constructor
* @param decl Declaration attributes
*/
XmlDeclaration(const NamedList& decl);
/**
* Copy constructor
* @param orig Original XmlDeclaration
*/
XmlDeclaration(const XmlDeclaration& orig);
/**
* Destructor
*/
~XmlDeclaration();
/**
* Obtain the tag name and attributes list
* @return The declaration
*/
inline const NamedList& getDec() const
{ return m_declaration; }
/**
* Get the Xml declaration
* @return This object
* Reimplemented from XmlChild
*/
virtual XmlDeclaration* xmlDeclaration()
{ return this; }
/**
* Build a String from this XmlDeclaration
* @param dump The string where to append representation
* @param escape True if the attributes values need to be escaped
* @return Destination buffer reference
*/
String& toString(String& dump, bool escape = true) const;
private:
NamedList m_declaration; // The declaration
};
/**
* Xml Fragment a fragment from a Xml document
* @short Xml Fragment
*/
class YATE_API XmlFragment : public XmlParent
{
friend class XmlElement;
public:
/**
* Constructor
*/
XmlFragment();
/**
* Copy constructor
* @param orig Original XmlFragment
*/
XmlFragment(const XmlFragment& orig);
/**
* Destructor
*/
virtual ~XmlFragment();
/**
* Get an Xml Fragment
* @return This
*/
virtual XmlFragment* fragment()
{ return this; }
/**
* Get the list of children
* @return The children list
*/
virtual const ObjList& getChildren() const
{ return m_list; }
/**
* Append a new xml child to this fragment
* @param child the child to append
* @return An error code if an error was detected
*/
virtual XmlSaxParser::Error addChild(XmlChild* child);
/**
* Reset this Xml Fragment
*/
virtual void reset();
/**
* Remove the first child from list and returns it
* @return XmlChild pointer or 0
*/
inline XmlChild* pop()
{ return static_cast<XmlChild*>(m_list.remove(false)); }
/**
* Remove the first XmlElement from list and returns it if completed
* @return XmlElement pointer or 0 if no XmlElement is found or the first one is not completed
*/
XmlElement* popElement();
/**
* Remove a child. Reset the parent of not deleted xml element