jxmlparser.h
61.8 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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
/***************************************************************************
* Copyright (C) 2005 by Lee Thomason <modified version> *
* root@sat *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
/**
* \brief Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason
* (www.grinninglizard.com)
*
* www.sourceforge.net/projects/tinyxml
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any
* damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any
* purpose, including commercial applications, and to alter it and
* redistribute it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must
* not claim that you wrote the original software. If you use this
* software in a product, an acknowledgment in the product documentation
* would be appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and
* must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef J_XMLPARSER_H
#define J_XMLPARSER_H
#include "jobject.h"
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdint.h>
/**
* \brief The support for explicit isn't that universal, and it isn't really
* required - it is used to check that the XmlString class isn't incorrectly
* used. Be nice to old compilers and macro it here:
*/
#if defined(_MSC_VER) && (_MSC_VER >= 1200 )
#define TIXML_EXPLICIT explicit // Microsoft visual studio, version 6 and higher.
#elif defined(__GNUC__) && (__GNUC__ >= 3 )
#define TIXML_EXPLICIT explicit // GCC version 3 and higher.s
#else
#define TIXML_EXPLICIT
#endif
#ifdef _MSC_VER
#pragma warning( push )
#pragma warning( disable : 4530 )
#pragma warning( disable : 4786 )
#endif
#if defined( _DEBUG ) && !defined( DEBUG ) // Help out windows:
#define DEBUG
#endif
/**
* \brief Deprecated library function hell. Compilers want to use the
* new safe versions. This probably doesn't fully address the problem,
* but it gets closer. There are too many compilers for me to fully
* test. If you get compilation troubles, undefine TIXML_SAFE
*/
#define TIXML_SAFE
#ifdef TIXML_SAFE
#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) // Microsoft visual studio, version 2005 and higher.
#define TIXML_SNPRINTF _snprintf_s
#define TIXML_SNSCANF _snscanf_s
#elif defined(_MSC_VER) && (_MSC_VER >= 1200 ) // Microsoft visual studio, version 6 and higher.
#define TIXML_SNPRINTF _snprintf
#define TIXML_SNSCANF _snscanf
#elif defined(__GNUC__) && (__GNUC__ >= 3 ) && !defined(__CYGWIN32__) // GCC version 3 and higher.s
#define TIXML_SNPRINTF snprintf
#define TIXML_SNSCANF snscanf
#endif
#endif
namespace jcommon {
class XmlDocument;
class XmlElement;
class XmlComment;
class XmlUnknown;
class XmlAttribute;
class XmlText;
class XmlDeclaration;
class XmlParsingData;
const int TIXML_MAJOR_VERSION = 2;
const int TIXML_MINOR_VERSION = 5;
const int TIXML_PATCH_VERSION = 1;
/**
* \brief Internal structure for tracking location of items in the XML file.
*/
struct XmlCursor{
/** \brief */
int row; // 0 based.
/** \brief */
int col; // 0 based.
/**
* \brief
*
*/
XmlCursor();
/**
* \brief
*
*/
void Clear();
};
/**
* \brief If you call the Accept() method, it requires being passed a XmlVisitor
* class to handle callbacks. For nodes that contain other nodes (Document, Element)
* you will get called with a VisitEnter/VisitExit pair. Nodes that are always leaves
* are simple called with Visit().
*
* If you return 'true' from a Visit method, recursive parsing will continue. If you return
* false, <b>no children of this node or its sibilings</b> will be Visited.
*
* All flavors of Visit methods have a default implementation that returns 'true' (continue
* visiting). You need to only override methods that are interesting to you.
*
* Generally Accept() is called on the XmlDocument, although all nodes suppert Visiting.
*
* You should never change the document from a callback.
*
* @sa XmlNode::Accept()
*/
class XmlVisitor{
private:
public:
/**
* \brief Destructor.
*
*/
virtual ~XmlVisitor();
/**
* \brief Visit a document.
*
*/
virtual bool VisitEnter(const XmlDocument& doc);
/**
* \brief Visit a document.
*
*/
virtual bool VisitExit(const XmlDocument& doc);
/**
* \brief Visit an element.
*
*/
virtual bool VisitEnter(const XmlElement& element, const XmlAttribute* firstAttribute);
/**
* \brief Visit an element.
*
*/
virtual bool VisitExit(const XmlElement& element);
/**
* \brief Visit a declaration.
*
*/
virtual bool Visit(const XmlDeclaration& declaration);
/**
* \brief Visit a text node
*
*/
virtual bool Visit(const XmlText& text);
/**
* \brief Visit a comment node
*
*/
virtual bool Visit(const XmlComment& comment);
/**
* \brief Visit an unknow node.
*
*/
virtual bool Visit(const XmlUnknown& unknown);
};
/**
* \brief Only used by Attribute::Query functions.
*
*/
enum {
TIXML_SUCCESS,
TIXML_NO_ATTRIBUTE,
TIXML_WRONG_TYPE
};
/**
* \brief Used by the parsing routines.
*
*/
enum XmlEncoding {
TIXML_ENCODING_UNKNOWN,
TIXML_ENCODING_UTF8,
TIXML_ENCODING_LEGACY
};
const XmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
/**
* \brief XmlBase is a base class for every class in nyXml.
* It does little except to establish that nyXml classes
* can be printed and provide some utility functions.
*
* In XML, the document and elements can contain
* other elements and other types of nodes.
*
* @verbatim
* A Document can contain: Element (container or leaf)
* Comment (leaf)
* Unknown (leaf)
* Declaration( leaf )
*
* An Element can contain: Element (container or leaf)
* Text (leaf)
* Attributes (not on tree)
* Comment (leaf)
* Unknown (leaf)
*
* A Decleration contains: Attributes (not on tree)
* @endverbatim
*/
class XmlBase{
friend class XmlNode;
friend class XmlElement;
friend class XmlDocument;
public:
enum {
TIXML_NO_ERROR = 0,
TIXML_ERROR,
TIXML_ERROR_OPENING_FILE,
TIXML_ERROR_OUT_OF_MEMORY,
TIXML_ERROR_PARSING_ELEMENT,
TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
TIXML_ERROR_READING_ELEMENT_VALUE,
TIXML_ERROR_READING_ATTRIBUTES,
TIXML_ERROR_PARSING_EMPTY,
TIXML_ERROR_READING_END_TAG,
TIXML_ERROR_PARSING_UNKNOWN,
TIXML_ERROR_PARSING_COMMENT,
TIXML_ERROR_PARSING_DECLARATION,
TIXML_ERROR_DOCUMENT_EMPTY,
TIXML_ERROR_EMBEDDED_NULL,
TIXML_ERROR_PARSING_CDATA,
TIXML_ERROR_DOCUMENT_TOP_ONLY,
TIXML_ERROR_STRING_COUNT
};
private:
/**
* \brief
*
*/
XmlBase(const XmlBase &);
/**
* \brief Not allowed.
*
*/
void operator=(const XmlBase &base);
struct Entity{
const char *str;
unsigned int strLength;
char chr;
};
enum {
NUM_ENTITY = 5,
MAX_ENTITY_LENGTH = 6
};
static Entity entity[NUM_ENTITY];
static bool condenseWhiteSpace;
protected:
/**
* \brief
*
*/
static const char * SkipWhiteSpace(const char *, XmlEncoding encoding);
/**
* \brief
*
*/
static bool IsWhiteSpace( char c );
/**
* \brief
*
*/
static bool IsWhiteSpace( int c );
/**
* \brief
*
*/
static bool StreamWhiteSpace(std::istream *in, std::string *tag);
/**
* \brief
*
*/
static bool StreamTo(std::istream *in, int character, std::string *tag);
/**
* \brief Reads an XML name into the string provided. Returns a pointer just
* past the last character of the name, or 0 if the function has an error.
*
*/
static const char * ReadName(const char *p, std::string *name, XmlEncoding encoding);
/**
* \brief Reads text. Returns a pointer past the given end tag. Wickedly complex options,
* but it keeps the (sensitive) code in one place.
*
* \param in Where to start.
* \param text The string read.
* \param ignoreWhiteSpace Whether to keep the white space.
* \param endTag What ends this text.
* \param ignoreCase Whether to ignore case in the end tag.
* \param enconding The current encoding.
*/
static const char * ReadText(const char* in, std::string* text, bool ignoreWhiteSpace, const char* endTag, bool ignoreCase, XmlEncoding encoding);
/**
* \brief If an entity has been found, transform it into a character.
*
*/
static const char * GetEntity(const char* in, char* value, int* length, XmlEncoding encoding);
/**
* \brief Get a character, while interpreting entities. The length can be from 0 to 4 bytes.
*
*/
static const char * GetChar(const char* p, char* _value, int* length, XmlEncoding encoding);
/**
* \brief Puts a string to a stream, expanding entities as it goes. Note this
* should not contian the '<', '>', etc, or they will be transformed into entities.
*
*/
static void PutString(const std::string& str, std::string* out);
/**
* \brief Return true if the next characters in the stream are any of the endTag sequences.
* Ignore case only works for english, and should only be relied on when comparing
* to English words: StringEqual( p, "version", true ) is fine.
*/
static bool StringEqual(const char *p, const char *endTag, bool ignoreCase, XmlEncoding encoding);
/**
* \brief
*
*/
static const char * errorString[TIXML_ERROR_STRING_COUNT];
XmlCursor location;
/** \brief Field containing a generic user pointer */
void *userData;
/**
* \brief None of these methods are reliable for any language except English.
* Good for approximation, not great for accuracy.
*
*/
static int IsAlpha(uint8_t anyByte, XmlEncoding encoding);
/**
* \brief
*
*/
static int IsAlphaNum(uint8_t anyByte, XmlEncoding encoding);
/**
* \brief
*
*/
static int ToLower(int v, XmlEncoding encoding);
/**
* \brief
*
*/
static void ConvertUTF32ToUTF8(unsigned long input, char *output, int *length);
public:
/**
* \brief
*
*/
XmlBase();
/**
* \brief
*
*/
virtual ~XmlBase();
/**
* \brief All nyXml classes can print themselves to a filestream or the string
* class (XmlString in non-STL mode, std::string in STL mode.) Either or both
* cfile and str can be null.
*
* This is a formatted print, and will insert tabs and newlines.
*
* (For an unformatted stream, use the << operator.)
*/
virtual void Print(FILE* cfile, int depth) const = 0;
/**
* The world does not agree on whether white space should be kept or not. In order
* to make everyone happy, these global, static functions are provided to set
* whether or not nyXml will condense all white space into a single space or not.
* The default is to condense. Note changing this value is not thread safe.
*/
static void SetCondenseWhiteSpace(bool condense);
/**
* \brief Return the current white space setting.
*
*/
static bool IsWhiteSpaceCondensed();
/**
* \brief Return the position, in the original source file, of this node or attribute.
* The row and column are 1-based. (That is the first row and first column is
* 1,1). If the returns values are 0 or less, then the parser does not have a row and
* column value.
*
* Generally, the row and column value will be set when the XmlDocument::Load(),
* XmlDocument::LoadFile(), or any XmlNode::Parse() is called. It will NOT be set
* when the DOM was created from operator>>.
*
* The values reflect the initial load. Once the DOM is modified programmatically
* (by adding or changing nodes and attributes) the new values will NOT update to
* reflect changes in the document.
*
* There is a minor performance cost to computing the row and column. Computation
* can be disabled if XmlDocument::SetTabSize() is called with 0 as the value.
*
* @sa XmlDocument::SetTabSize()
*/
int Row() const;
/**
* \brief
*
*/
int Column() const; // SEE Row
/**
* \brief
*
*/
void SetUserData(void *user);
/**
* \brief
*
*/
void * GetUserData();
/**
* \brief
*
*/
const void * GetUserData() const;
/**
* \brief Table that returs, for a given lead byte, the total number of bytes
* in the UTF-8 sequence.
*
*/
static const int utf8ByteTable[256];
/**
* \brief
*
* \param encoding TIXML_ENCODING_UNKNOWN
*/
virtual const char * Parse(const char *p, XmlParsingData *data, XmlEncoding encoding) = 0;
};
/**
* \brief The parent class for everything in the Document Object Model.
* (Except for attributes). Nodes have siblings, a parent, and children.
* A node can be in a document, or stand on its own. The type of a
* XmlNode can be queried, and it can be cast to its more defined type.
*/
class XmlNode : public XmlBase{
friend class XmlDocument;
friend class XmlElement;
public:
/**
* \brief An input stream operator, for every class. Tolerant of newlines and
* formatting, but doesn't expect them.
*
*/
friend std::istream& operator >> (std::istream& in, XmlNode& base);
/**
* \brief An output stream operator, for every class. Note that this outputs
* without any newlines or formatting, as opposed to Print(), which includes
* tabs and new lines.
*
* The operator<< and operator>> are not completely symmetric. Writing a node
* to a stream is very well defined. You'll get a nice stream of output, without
* any extra whitespace or newlines.
*
* But reading is not as well defined. (As it always is.) If you create a XmlElement
* (for example) and read that from an input stream, the text needs to define an
* element or junk will result. This is true of all input streams, but it's worth
* keeping in mind.
*
* A XmlDocument will read nodes until it reads a root element, and all the children
* of that root element.
*/
friend std::ostream& operator<< (std::ostream& out, const XmlNode& base);
/**
* \brief Appends the XML node or attribute to a std::string.
*
*/
friend std::string& operator<< (std::string& out, const XmlNode& base );
/**
* \brief The types of XML nodes supported by nyXml. (All the unsupported types
* are picked up by UNKNOWN)
*
*/
enum NodeType {
DOCUMENT,
ELEMENT,
COMMENT,
UNKNOWN,
TEXT,
DECLARATION,
TYPECOUNT
};
/**
* \brief
*
*/
virtual ~XmlNode();
/**
* \brief The meaning of 'value' changes for the specific type of XmlNode.
* @verbatim
* Document: filename of the xml file
* Element: name of the element
* Comment: the comment text
* Unknown: the tag contents
* Text: the text string
* @endverbatim
*
* The subclasses will wrap this function.
*/
const char * Value() const;
/**
* \brief Return Value() as a std::string. If you only use STL, this is more
* efficient than calling Value(). Only available in STL mode.
*
*/
const std::string & ValueStr() const;
/**
* \brief Changes the value of the node. Defined as:
* @verbatim
* Document: filename of the xml file
* Element: name of the element
* Comment: the comment text
* Unknown: the tag contents
* Text: the text string
* @endverbatim
*/
void SetValue(const char * _value);
/**
* \brief STL std::string form.
*
*/
void SetValue( const std::string& _value ) ;
/**
* \brief Delete all the children of this node. Does not affect 'this'.
*
*/
void Clear();
/**
* \brief One step up the DOM.
*
*/
XmlNode* Parent();
/**
* \brief
*
*/
const XmlNode* Parent() const;
/**
* \brief
*
*/
const XmlNode* FirstChild() const;
/**
* \brief
*
*/
XmlNode* FirstChild();
/**
* \brief The first child of this node with the matching 'value'. Will be null
* if none found.
*
*/
const XmlNode* FirstChild( const char * value ) const;
/**
* \brief The first child of this node with the matching 'value'. Will be null if none found.
*
*/
XmlNode* FirstChild( const char * _value );
/**
* \brief
*
*/
const XmlNode* LastChild() const ;
/**
* \brief
*
*/
XmlNode* LastChild() ;
/**
* \brief
*
*/
const XmlNode* LastChild( const char * value ) const; /// The last child of this node matching 'value'. Will be null if there are no children.
/**
* \brief
*
*/
XmlNode* LastChild( const char * _value ) ;
/**
* \brief
*
*/
const XmlNode* FirstChild( const std::string& _value ) const ;
/**
* \brief
*
*/
XmlNode* FirstChild( const std::string& _value );
/**
* \brief
*
*/
const XmlNode* LastChild( const std::string& _value ) const ;
/**
* \brief
*
*/
XmlNode* LastChild( const std::string& _value );
/** An alternate way to walk the children of a node.
One way to iterate over nodes is:
@verbatim
for( child = parent->FirstChild(); child; child = child->NextSibling() )
@endverbatim
IterateChildren does the same thing with the syntax:
@verbatim
child = 0;
while( child = parent->IterateChildren( child ) )
@endverbatim
IterateChildren takes the previous child as input and finds
the next one. If the previous child is null, it returns the
first. IterateChildren will return null when done.
*/
const XmlNode* IterateChildren( const XmlNode* previous ) const;
/**
* \brief
*
*/
XmlNode* IterateChildren( XmlNode* previous ) ;
/**
* \brief This flavor of IterateChildren searches for children with a particular 'value'
*
*/
const XmlNode* IterateChildren( const char * value, const XmlNode* previous ) const;
/**
* \brief
*
*/
XmlNode* IterateChildren( const char * _value, XmlNode* previous ) ;
/**
* \brief
*
*/
const XmlNode* IterateChildren( const std::string& _value, const XmlNode* previous ) const;
/**
* \brief
*
*/
XmlNode* IterateChildren( const std::string& _value, XmlNode* previous );
/** Add a new node related to this. Adds a child past the LastChild.
Returns a pointer to the new object or NULL if an error occured.
*/
XmlNode* InsertEndChild( const XmlNode& addThis );
/** Add a new node related to this. Adds a child past the LastChild.
NOTE: the node to be added is passed by pointer, and will be
henceforth owned (and deleted) by tinyXml. This method is efficient
and avoids an extra copy, but should be used with care as it
uses a different memory model than the other insert functions.
@sa InsertEndChild
*/
XmlNode* LinkEndChild( XmlNode* addThis );
/** Add a new node related to this. Adds a child before the specified child.
Returns a pointer to the new object or NULL if an error occured.
*/
XmlNode* InsertBeforeChild( XmlNode* beforeThis, const XmlNode& addThis );
/** Add a new node related to this. Adds a child after the specified child.
Returns a pointer to the new object or NULL if an error occured.
*/
XmlNode* InsertAfterChild( XmlNode* afterThis, const XmlNode& addThis );
/** Replace a child of this node.
Returns a pointer to the new object or NULL if an error occured.
*/
XmlNode* ReplaceChild( XmlNode* replaceThis, const XmlNode& withThis );
/**
* \brief Delete a child of this node.
*
*/
bool RemoveChild( XmlNode* removeThis );
/**
* \brief Navigate to a sibling node.
*
*/
const XmlNode* PreviousSibling() const;
/**
* \brief
*
*/
XmlNode* PreviousSibling();
/**
* \brief Navigate to a sibling node.
*
*/
const XmlNode* PreviousSibling( const char * ) const;
/**
* \brief
*
*/
XmlNode* PreviousSibling( const char *_prev ) ;
/**
* \brief
*
*/
const XmlNode* PreviousSibling( const std::string& _value ) const;
/**
* \brief
*
*/
XmlNode* PreviousSibling( const std::string& _value );
/**
* \brief
*
*/
const XmlNode* NextSibling( const std::string& _value) const;
/**
* \brief
*
*/
XmlNode* NextSibling( const std::string& _value) ;
/**
* \brief Navigate to a sibling node.
*
*/
const XmlNode* NextSibling() const ;
/**
* \brief
*
*/
XmlNode* NextSibling() ;
/**
* \brief Navigate to a sibling node with the given 'value'.
*
*/
const XmlNode* NextSibling( const char * ) const;
/**
* \brief
*
*/
XmlNode* NextSibling( const char* _next ) ;
/** Convenience function to get through elements.
Calls NextSibling and ToElement. Will skip all non-Element
nodes. Returns 0 if there is not another element.
*/
const XmlElement* NextSiblingElement() const;
/**
* \brief
*
*/
XmlElement* NextSiblingElement() ;
/**
* Convenience function to get through elements.
* Calls NextSibling and ToElement. Will skip all non-Element
* nodes. Returns 0 if there is not another element.
*/
const XmlElement* NextSiblingElement( const char * ) const;
/**
* \brief
*
*/
XmlElement* NextSiblingElement( const char *_next );
/**
* \brief
*
*/
const XmlElement* NextSiblingElement( const std::string& _value) const;
/**
* \brief
*
*/
XmlElement* NextSiblingElement( const std::string& _value);
/**
* \brief Convenience function to get through elements.
*
*/
const XmlElement* FirstChildElement() const;
/**
* \brief
*
*/
XmlElement* FirstChildElement() ;
/**
* \brief Convenience function to get through elements.
*
*/
const XmlElement* FirstChildElement( const char * _value ) const;
/**
* \brief
*
*/
XmlElement* FirstChildElement( const char * _value );
/**
* \brief
*
*/
const XmlElement* FirstChildElement( const std::string& _value ) const ;
/**
* \brief
*
*/
XmlElement* FirstChildElement( const std::string& _value );
/**
* \brief Query the type (as an enumerated value, above) of this node.
* The possible types are: DOCUMENT, ELEMENT, COMMENT, UNKNOWN, TEXT, and DECLARATION.
*
*/
int Type() const;
/**
* Return a pointer to the Document this node lives in. Returns null if not in a document.
*
*/
const XmlDocument* GetDocument() const;
/**
* \brief
*
*/
XmlDocument* GetDocument();
/**
* \brief Returns true if this node has no children.
*
*/
bool HasChildren() const;
/**
* \brief
*
*/
virtual const XmlDocument* ToDocument() const;
/**
* \brief
*
*/
virtual const XmlElement* ToElement() const ;
/**
* \brief
*
*/
virtual const XmlComment* ToComment() const ;
/**
* \brief
*
*/
virtual const XmlUnknown* ToUnknown() const;
/**
* \brief
*
*/
virtual const XmlText* ToText() const ;
/**
* \brief
*
*/
virtual const XmlDeclaration* ToDeclaration() const;
/**
* \brief
*
*/
virtual XmlDocument* ToDocument() ;
/**
* \brief
*
*/
virtual XmlElement* ToElement() ;
/**
* \brief
*
*/
virtual XmlComment* ToComment() ;
/**
* \brief
*
*/
virtual XmlUnknown* ToUnknown() ;
/**
* \brief
*
*/
virtual XmlText* ToText() ;
/**
* \brief
*
*/
virtual XmlDeclaration* ToDeclaration();
/** Create an exact duplicate of this node and return it. The memory must be deleted
by the caller.
*/
virtual XmlNode* Clone() const = 0;
/** Accept a hierchical visit the nodes in the nyXML DOM. Every node in the
XML tree will be conditionally visited and the host will be called back
via the XmlVisitor interface.
This is essentially a SAX interface for nyXML. (Note however it doesn't re-parse
the XML for the callbacks, so the performance of nyXML is unchanged by using this
interface versus any other.)
The interface has been based on ideas from:
- http://www.saxproject.org/
- http://c2.com/cgi/wiki?HierarchicalVisitorPattern
Which are both good references for "visiting".
An example of using Accept():
@verbatim
XmlPrinter printer;
tinyxmlDoc.Accept( &printer );
const char* xmlcstr = printer.CStr();
@endverbatim
*/
virtual bool Accept( XmlVisitor* visitor ) const = 0;
protected:
/**
* \brief
*
*/
XmlNode( NodeType _type );
/**
* \brief Copy to the allocated object. Shared functionality between Clone,
* Copy constructor, and the assignment operator.
*
*/
void CopyTo( XmlNode* target ) const;
/**
* \brief The real work of the input operator.
*
*/
virtual void StreamIn( std::istream* in, std::string* tag ) = 0;
/**
* \brief Figure out what is at *p, and parse it. Returns null if it is not an xml node.
*
*/
XmlNode* Identify( const char* start, XmlEncoding encoding );
XmlNode* parent;
NodeType type;
XmlNode* firstChild;
XmlNode* lastChild;
std::string value;
XmlNode* prev;
XmlNode* next;
private:
/**
* \brief
*
*/
XmlNode( const XmlNode& ); // not implemented.
/**
* \brief
*
*/
void operator=( const XmlNode& base ); // not allowed.
};
/** An attribute is a name-value pair. Elements have an arbitrary
number of attributes, each with a unique name.
@note The attributes are not XmlNodes, since they are not
part of the tinyXML document object model. There are other
suggested ways to look at this problem.
*/
class XmlAttribute : public XmlBase
{
friend class XmlAttributeSet;
public:
/**
* \brief Construct an empty attribute.
*
*/
XmlAttribute();
/**
* \brief std::string constructor.
*
*/
XmlAttribute( const std::string& _name, const std::string& _value );
/**
* \brief Construct an attribute with a name and value.
*
*/
XmlAttribute( const char * _name, const char * _value );
/**
* \brief
*
*/
const char* Name() const;
/**
* \brief
*
*/
const char* Value() const;
/**
* \brief
*
*/
const std::string& ValueStr() const ;
/**
* \brief
*
*/
int IntValue() const; ///< Return the value of this attribute, converted to an integer.
/**
* \brief
*
*/
double DoubleValue() const; ///< Return the value of this attribute, converted to a double.
// Get the tinyxml string representation
const std::string& NameTStr() const ;
/** QueryIntValue examines the value string. It is an alternative to the
IntValue() method with richer error checking.
If the value is an integer, it is stored in 'value' and
the call returns TIXML_SUCCESS. If it is not
an integer, it returns TIXML_WRONG_TYPE.
A specialized but useful call. Note that for success it returns 0,
which is the opposite of almost all other nyXml calls.
*/
int QueryIntValue( int* _value ) const;
/**
* \brief QueryDoubleValue examines the value string. See QueryIntValue().
*
*/
int QueryDoubleValue( double* _value ) const;
/**
* \brief
*
*/
void SetName( const char* _name ) ;
/**
* \brief
*
*/
void SetValue( const char* _value ) ;
/**
* \brief
*
*/
void SetIntValue( int _value ); ///< Set the value from an integer.
/**
* \brief
*
*/
void SetDoubleValue( double _value ); ///< Set the value from a double.
/**
* \brief STL std::string form.
*
*/
void SetName( const std::string& _name );
/**
* \brief STL std::string form.
*
*/
void SetValue( const std::string& _value );
/**
* \brief Get the next sibling attribute in the DOM. Returns null at end.
*
*/
const XmlAttribute* Next() const;
/**
* \brief
*
*/
XmlAttribute* Next() ;
/**
* \brief Get the previous sibling attribute in the DOM. Returns null at beginning.
*
*/
const XmlAttribute* Previous() const;
/**
* \brief
*
*/
XmlAttribute* Previous() ;
/**
* \brief
*
*/
bool operator==( const XmlAttribute& rhs ) const ;
/**
* \brief
*
*/
bool operator<( const XmlAttribute& rhs ) const;
/**
* \brief
*
*/
bool operator>( const XmlAttribute& rhs ) const ;
/* Attribute parsing starts: first letter of the name returns:
* the next char after the value end quote
*
*/
virtual const char* Parse( const char* p, XmlParsingData* data, XmlEncoding encoding );
/**
* \brief Prints this Attribute to a FILE stream.
*
*/
virtual void Print( FILE* cfile, int depth ) const ;
/**
* \brief
*
*/
void Print( FILE* cfile, int depth, std::string* str ) const;
/**
* \brief Set the document pointer so the attribute can report errors.
*
*/
void SetDocument( XmlDocument* doc );
private:
/**
* \brief
*
*/
XmlAttribute( const XmlAttribute& ); // not implemented.
/**
* \brief
*
*/
void operator=( const XmlAttribute& base ); // not allowed.
XmlDocument* document; // A pointer back to a document, for error reporting.
std::string name;
std::string value;
XmlAttribute* prev;
XmlAttribute* next;
};
/* A class used to manage a group of attributes.
It is only used internally, both by the ELEMENT and the DECLARATION.
The set can be changed transparent to the Element and Declaration
classes that use it, but NOT transparent to the Attribute
which has to implement a next() and previous() method. Which makes
it a bit problematic and prevents the use of STL.
This version is implemented with circular lists because:
- I like circular lists
- it demonstrates some independence from the (typical) doubly linked list.
*/
class XmlAttributeSet {
public:
/**
* \brief
*
*/
XmlAttributeSet();
/**
* \brief
*
*/
~XmlAttributeSet();
/**
* \brief
*
*/
void Add( XmlAttribute* attribute );
/**
* \brief
*
*/
void Remove( XmlAttribute* attribute );
/**
* \brief
*
*/
const XmlAttribute* First() const;
/**
* \brief
*
*/
XmlAttribute* First() ;
/**
* \brief
*
*/
const XmlAttribute* Last() const;
/**
* \brief
*
*/
XmlAttribute* Last();
/**
* \brief
*
*/
const XmlAttribute* Find( const char* _name ) const;
/**
* \brief
*
*/
XmlAttribute* Find( const char* _name ) ;
/**
* \brief
*
*/
const XmlAttribute* Find( const std::string& _name ) const;
/**
* \brief
*
*/
XmlAttribute* Find( const std::string& _name ) ;
private:
// ME: Because of hidden/disabled copy-construktor in XmlAttribute (sentinel-element),
// ME: this class must be also use a hidden/disabled copy-constructor !!!
XmlAttributeSet( const XmlAttributeSet& ); // not allowed
/**
* \brief
*
*/
void operator=( const XmlAttributeSet& ); // not allowed (as XmlAttribute)
XmlAttribute sentinel;
};
/** The element is a container class. It has a value, the element name,
and can contain other elements, text, comments, and unknowns.
Elements also contain an arbitrary number of attributes.
*/
class XmlElement : public XmlNode
{
public:
/**
* \brief Construct an element.
*
*/
XmlElement (const char * in_value);
/**
* \brief std::string constructor.
*
*/
XmlElement( const std::string& _value );
/**
* \brief
*
*/
XmlElement( const XmlElement& );
/**
* \brief
*
*/
void operator=( const XmlElement& base );
/**
* \brief
*
*/
virtual ~XmlElement();
/**
* \brief Given an attribute name, Attribute() returns the value
* for the attribute of that name, or null if none exists.
*
*/
const char* Attribute( std::string name ) const;
/**
* \brief Given an attribute name, Attribute() returns the value for the
* attribute of that name, or null if none exists. If the attribute
* exists and can be converted to an integer, the integer value will
* be put in the return 'i', if 'i' is non-null.
*/
const char* Attribute( std::string name, int* i ) const;
/**
* \brief Given an attribute name, Attribute() returns the value
* for the attribute of that name, or null if none exists.
* If the attribute exists and can be converted to an double,
* the double value will be put in the return 'd', if 'd' is non-null.
*
*/
const char* Attribute( std::string name, double* d ) const;
/**
* \brief Given an attribute name, Attribute() returns the value
* for the attribute of that name, or null if none exists.
*
*/
const char* Attribute( const char* name ) const;
/**
* \brief Given an attribute name, Attribute() returns the value for the
* attribute of that name, or null if none exists. If the attribute
* exists and can be converted to an integer, the integer value will
* be put in the return 'i', if 'i' is non-null.
*/
const char* Attribute( const char* name, int* i ) const;
/**
* \brief Given an attribute name, Attribute() returns the value
* for the attribute of that name, or null if none exists.
* If the attribute exists and can be converted to an double,
* the double value will be put in the return 'd', if 'd' is non-null.
*
*/
const char* Attribute( const char* name, double* d ) const;
/**
* \brief QueryIntAttribute examines the attribute - it is an alternative to the
* Attribute() method with richer error checking. If the attribute is an integer,
* it is stored in 'value' and the call returns TIXML_SUCCESS. If it is not
* an integer, it returns TIXML_WRONG_TYPE. If the attribute does not exist,
* then TIXML_NO_ATTRIBUTE is returned.
*
*/
int QueryIntAttribute( const char* name, int* _value ) const;
/**
* \brief QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
*
*/
int QueryDoubleAttribute( const char* name, double* _value ) const;
/**
* \brief QueryFloatAttribute examines the attribute - see QueryIntAttribute().
*
*/
int QueryFloatAttribute( const char* name, float* _value ) const ;
/**
* Template form of the attribute query which will try to read the
* attribute into the specified type. Very easy, very powerful, but
* be careful to make sure to call this with the correct type.
*
* \return TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBUTE
*
*/
template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const
{
const XmlAttribute* node = attributeSet.Find( name );
if ( !node )
return TIXML_NO_ATTRIBUTE;
std::stringstream sstream( node->ValueStr() );
sstream >> *outValue;
if ( !sstream.fail() )
return TIXML_SUCCESS;
return TIXML_WRONG_TYPE;
}
/**
* \brief Sets an attribute of name to a given value. The attribute
* will be created if it does not exist, or changed if it does.
*
*/
void SetAttribute( const char* name, const char * _value );
/**
* \brief
*
*/
int QueryIntAttribute( const std::string& name, int* _value ) const;
/**
* \brief
*
*/
int QueryDoubleAttribute( const std::string& name, double* _value ) const;
/**
* \brief
*
*/
void SetAttribute( const std::string& name, const std::string& _value );
/**
* \brief
*
*/
void SetAttribute( const std::string& name, int _value );
/** Sets an attribute of name to a given value. The attribute
will be created if it does not exist, or changed if it does.
*/
void SetAttribute( const char * name, int value );
/**
* \brief Sets an attribute of name to a given value. The attribute
* will be created if it does not exist, or changed if it does.
*
*/
void SetDoubleAttribute( const char * name, double value );
/**
* \brief Deletes an attribute with the given name.
*
*/
void RemoveAttribute( const char * name );
/**
* \brief
*
*/
void RemoveAttribute( const std::string& name );
/**
* \brief
*
*/
const XmlAttribute* FirstAttribute() const ;
/**
* \brief
*
*/
XmlAttribute* FirstAttribute();
/**
* \brief
*
*/
const XmlAttribute* LastAttribute() const ;
/**
* \brief
*
*/
XmlAttribute* LastAttribute();
/** Convenience function for easy access to the text inside an element. Although easy
and concise, GetText() is limited compared to getting the XmlText child
and accessing it directly.
If the first child of 'this' is a XmlText, the GetText()
returns the character string of the Text node, else null is returned.
This is a convenient method for getting the text of simple contained text:
@verbatim
<foo>This is text</foo>
const char* str = fooElement->GetText();
@endverbatim
'str' will be a pointer to "This is text".
Note that this function can be misleading. If the element foo was created from
this XML:
@verbatim
<foo><b>This is text</b></foo>
@endverbatim
then the value of str would be null. The first child node isn't a text node, it is
another element. From this XML:
@verbatim
<foo>This is <b>text</b></foo>
@endverbatim
GetText() will return "This is ".
WARNING: GetText() accesses a child node - don't become confused with the
similarly named XmlHandle::Text() and XmlNode::ToText() which are
safe type casts on the referenced node.
*/
std::string GetText() const;
/**
* \brief Creates a new Element and returns it - the returned element is a copy.
*
*/
virtual XmlNode* Clone() const;
/**
* \brief Print the Element to a FILE stream.
*
*/
virtual void Print( FILE* cfile, int depth ) const;
/**
* \brief Attribtue parsing starts: next char past '<' returns: next char past '>'
*
*/
virtual const char* Parse( const char* p, XmlParsingData* data, XmlEncoding encoding );
/**
* \brief
*
*/
virtual const XmlElement* ToElement() const ;
/**
* \brief
*
*/
virtual XmlElement* ToElement();
/** Walk the XML tree visiting this node and all of its children.
*/
virtual bool Accept( XmlVisitor* visitor ) const;
protected:
/**
* \brief
*
*/
void CopyTo( XmlElement* target ) const;
/**
* \brief Like clear, but initializes 'this' object as well
*
*/
void ClearThis();
/**
* \brief Used to be public [internal use]
*
*/
virtual void StreamIn( std::istream * in, std::string * tag );
/**
* \brief Reads the "value" of the element -- another element, or text.
* This should terminate with the current end tag.
*
*/
const char* ReadValue( const char* in, XmlParsingData* prevData, XmlEncoding encoding );
private:
XmlAttributeSet attributeSet;
};
/**
* \brief An XML comment.
*
*/
class XmlComment : public XmlNode
{
public:
/**
* \brief Constructs an empty comment.
*
*/
XmlComment();
/**
* \brief Construct a comment from text.
*
*/
XmlComment( const char* _value );
/**
* \brief
*
*/
XmlComment( const XmlComment& );
/**
* \brief
*
*/
void operator=( const XmlComment& base );
/**
* \brief
*
*/
virtual ~XmlComment();
/**
* \brief Returns a copy of this Comment.
*
*/
virtual XmlNode* Clone() const;
/**
* \brief Write this Comment to a FILE stream.
*
*/
virtual void Print( FILE* cfile, int depth ) const;
/**
* \brief Attribtue parsing starts: at the ! of the !-- returns: next char past '>'
*
*/
virtual const char* Parse( const char* p, XmlParsingData* data, XmlEncoding encoding );
/**
* \brief Cast to a more defined type. Will return null not of the requested type.
*
*/
virtual const XmlComment* ToComment() const;
/**
* \brief Cast to a more defined type. Will return null not of the requested type.
*
*/
virtual XmlComment* ToComment() ;
/**
* \brief Walk the XML tree visiting this node and all of its children.
*
*/
virtual bool Accept( XmlVisitor* visitor ) const;
protected:
/**
* \brief
*
*/
void CopyTo( XmlComment* target ) const;
/**
* \brief used to be public
*
*/
virtual void StreamIn( std::istream * in, std::string * tag );
// virtual void StreamOut( TIXML_OSTREAM * out ) const;
private:
};
/**
* \brief XML text. A text node can have 2 ways to output the next. "normal" output
* and CDATA. It will default to the mode it was parsed from the XML file and
* you generally want to leave it alone, but you can change the output mode with
* SetCDATA() and query it with CDATA().
*
*/
class XmlText : public XmlNode{
friend class XmlElement;
public:
/**
* \brief Constructor for text element. By default, it is treated as
* normal, encoded text. If you want it be output as a CDATA text
* element, set the parameter _cdata to 'true'
*
*/
XmlText (const char * initValue );
/**
* \brief
*
*/
virtual ~XmlText() ;
/**
* \brief
*
*/
XmlText( const std::string& initValue );
/**
* \brief
*
*/
XmlText( const XmlText& copy ) ;
/**
* \brief
*
*/
void operator=( const XmlText& base );
/**
* \brief Write this text object to a FILE stream.
*
*/
virtual void Print( FILE* cfile, int depth ) const;
/**
* \brief Queries whether this represents text using a CDATA section.
*
*/
bool CDATA() const;
/**
* \brief Turns on or off a CDATA representation of text.
*
*/
void SetCDATA( bool _cdata );
/**
* \brief
*
*/
virtual const char* Parse( const char* p, XmlParsingData* data, XmlEncoding encoding );
/**
* \brief Cast to a more defined type. Will return null not of the requested type.
*
*/
virtual const XmlText* ToText() const;
/**
* \brief Cast to a more defined type. Will return null not of the requested type.
*
*/
virtual XmlText * ToText();
/**
* \brief Walk the XML tree visiting this node and all of its children.
*
*/
virtual bool Accept( XmlVisitor* content ) const;
protected :
/**
* \brief Creates a new Element and returns it.
*
*/
virtual XmlNode* Clone() const;
/**
* \brief
*
*/
void CopyTo( XmlText* target ) const;
/**
* \brief Returns true if all white space and new lines.
*
*/
bool Blank() const;
/**
* \brief
*
*/
virtual void StreamIn( std::istream * in, std::string * tag );
private:
bool cdata; // true if this should be input and output as a CDATA style text element
};
/**
* \brief In correct XML the declaration is the first entry in the file.
* @verbatim
* <?xml version="1.0" standalone="yes"?>
* @endverbatim
*
* nyXml will happily read or write files without a declaration,
* however. There are 3 possible attributes to the declaration:
* version, encoding, and standalone.
*
* Note: In this version of the code, the attributes are
* handled as special cases, not generic attributes, simply
* because there can only be at most 3 and they are always the same.
*/
class XmlDeclaration : public XmlNode{
public:
/**
* \brief Construct an empty declaration.
*
*/
XmlDeclaration();
/**
* \brief Constructor.
*
*/
XmlDeclaration(const std::string& _version,
const std::string& _encoding,
const std::string& _standalone );
/**
* \brief Construct.
*
*/
XmlDeclaration(const char* _version,
const char* _encoding,
const char* _standalone );
/**
* \brief
*
*/
XmlDeclaration( const XmlDeclaration& copy );
/**
* \brief
*
*/
void operator=( const XmlDeclaration& copy );
/**
* \brief
*
*/
virtual ~XmlDeclaration();
/**
* \brief Version. Will return an empty string if none was found.
*
*/
const char *Version() const ;
/**
* \brief Encoding. Will return an empty string if none was found.
*
*/
const char *Encoding() const;
/**
* \brief Is this a standalone document?
*
*/
const char *Standalone() const;
/**
* \brief Creates a copy of this Declaration and returns it.
*
*
*/
virtual XmlNode* Clone() const;
/**
* \brief Print this declaration to a FILE stream.
*
*/
virtual void Print( FILE* cfile, int depth, std::string* str ) const;
/**
* \brief
*
*/
virtual void Print( FILE* cfile, int depth ) const ;
/**
* \brief
*
*/
virtual const char* Parse( const char* p, XmlParsingData* data, XmlEncoding encoding );
/**
* \brief
*
*/
virtual const XmlDeclaration* ToDeclaration() const ;
/**
* \brief
*
*/
virtual XmlDeclaration* ToDeclaration();
/**
* \brief Walk the XML tree visiting this node and all of its children.
*
*/
virtual bool Accept( XmlVisitor* visitor ) const;
protected:
/**
* \brief
*
*/
void CopyTo( XmlDeclaration* target ) const;
/**
* \brief used to be public
*
*/
virtual void StreamIn( std::istream * in, std::string * tag );
private:
std::string version;
std::string encoding;
std::string standalone;
};
/**
* \brief Any tag that tinyXml doesn't recognize is saved as an
* unknown. It is a tag of text, but should not be modified.
* It will be written back to the XML, unchanged, when the file
* is saved.
*
* DTD tags get thrown into XmlUnknowns.
*/
class XmlUnknown : public XmlNode{
public:
/**
* \brief
*
*/
XmlUnknown() ;
/**
* \brief
*
*/
virtual ~XmlUnknown() ;
/**
* \brief
*
*/
XmlUnknown( const XmlUnknown& copy ) ;
/**
* \brief
*
*/
void operator=( const XmlUnknown& copy );
/**
* \brief Creates a copy of this Unknown and returns it.
*
*/
virtual XmlNode* Clone() const;
/**
* \brief Print this Unknown to a FILE stream.
*
*/
virtual void Print( FILE* cfile, int depth ) const;
/**
* \brief
*
*/
virtual const char* Parse( const char* p, XmlParsingData* data, XmlEncoding encoding );
/**
* \brief
*
*/
virtual const XmlUnknown* ToUnknown() const;
/**
* \brief
*
*/
virtual XmlUnknown* ToUnknown() ;
/**
* \brief Walk the XML tree visiting this node and all of its children.
*
*/
virtual bool Accept( XmlVisitor* content ) const;
protected:
/**
* \brief
*
*/
void CopyTo( XmlUnknown* target ) const;
/**
* \brief
*
*/
virtual void StreamIn( std::istream * in, std::string * tag );
private:
};
/**
* \brief Always the top level node. A document binds together all the
* XML pieces. It can be saved, loaded, and printed to the screen.
* The 'value' of a document node is the xml file name.
*
*/
class XmlDocument : public XmlNode{
public:
/**
* \brief Create an empty document, that has no name.
*
*/
XmlDocument();
/**
* \brief Create a document with a name. The name of the document is also
* the filename of the xml.
*
*/
XmlDocument( const char * documentName );
/**
* \brief Constructor.
*
*/
XmlDocument( const std::string& documentName );
/**
* \brief
*
*/
XmlDocument( const XmlDocument& copy );
/**
* \brief
*
*/
void operator=( const XmlDocument& copy );
/**
* \brief
*
*/
virtual ~XmlDocument();
/**
* \brief Load a file using the current document value. Returns true
* if successful. Will delete any existing document data before loading.
*
*/
bool LoadFile( XmlEncoding encoding = TIXML_DEFAULT_ENCODING );
/**
* \brief Save a file using the current document value. Returns true if successful.
*
*/
bool SaveFile() const;
/**
* \brief Load a file using the given filename. Returns true if successful.
*
*/
bool LoadFile( const char * filename, XmlEncoding encoding = TIXML_DEFAULT_ENCODING );
/**
* \brief Save a file using the given filename. Returns true if successful.
*
*/
bool SaveFile( const char * filename ) const;
/**
* \brief Load a file using the given FILE*. Returns true if successful. Note that
* this method doesn't stream - the entire object pointed at by the FILE* will be
* interpreted as an XML file. nyXML doesn't stream in XML from the current file
* location. Streaming may be added in the future.
*
*/
bool LoadFile( FILE*, XmlEncoding encoding = TIXML_DEFAULT_ENCODING );
/**
* \brief Save a file using the given FILE*. Returns true if successful.
*
*/
bool SaveFile( FILE* ) const;
/**
* \brief
*
*/
bool LoadFile( const std::string& filename, XmlEncoding encoding = TIXML_DEFAULT_ENCODING );
/**
* \brief
*
*/
bool SaveFile( const std::string& filename ) const; ///< STL std::string version.
/** Parse the given null terminated block of xml data. Passing in an encoding to this
method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force nyXml
to use that encoding, regardless of what nyXml might otherwise try to detect.
*/
virtual const char* Parse( const char* p, XmlParsingData* data = 0, XmlEncoding encoding = TIXML_DEFAULT_ENCODING );
/** Get the root element -- the only top level element -- of the document.
In well formed XML, there should only be one. nyXml is tolerant of
multiple elements at the document level.
*/
const XmlElement* RootElement() const ;
XmlElement* RootElement();
/** If an error occurs, Error will be set to true. Also,
- The ErrorId() will contain the integer identifier of the error (not generally useful)
- The ErrorDesc() method will return the name of the error. (very useful)
- The ErrorRow() and ErrorCol() will return the location of the error (if known)
*/
bool Error() const;
/// Contains a textual (english) description of the error if one occurs.
const char * ErrorDesc() const ;
/** Generally, you probably want the error string ( ErrorDesc() ). But if you
prefer the ErrorId, this function will fetch it.
*/
int ErrorId() const;
/** Returns the location (if known) of the error. The first column is column 1,
and the first row is row 1. A value of 0 means the row and column wasn't applicable
(memory errors, for example, have no row/column) or the parser lost the error. (An
error in the error reporting, in that case.)
@sa SetTabSize, Row, Column
*/
int ErrorRow();
int ErrorCol() ;
/** SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol())
to report the correct values for row and column. It does not change the output
or input in any way.
By calling this method, with a tab size
greater than 0, the row and column of each node and attribute is stored
when the file is loaded. Very useful for tracking the DOM back in to
the source file.
The tab size is required for calculating the location of nodes. If not
set, the default of 4 is used. The tabsize is set per document. Setting
the tabsize to 0 disables row/column tracking.
Note that row and column tracking is not supported when using operator>>.
The tab size needs to be enabled before the parse or load. Correct usage:
@verbatim
XmlDocument doc;
doc.SetTabSize( 8 );
doc.Load( "myfile.xml" );
@endverbatim
@sa Row, Column
*/
void SetTabSize( int _tabsize ) ;
int TabSize() const;
/**
* \brief If you have handled the error, it can be reset with this call. The error
* state is automatically cleared if you Parse a new XML block.
*
*/
void ClearError();
/**
* \brief Write the document to standard out using formatted printing ("pretty print").
*
*/
void Print() const;
/**
* \brief Write the document to a string using formatted printing ("pretty print").
* This will allocate a character array (new char[]) and return it as a pointer. The
* calling code pust call delete[] on the return char* to avoid a memory leak.
*
*/
//char* PrintToMemory() const;
/**
* \brief Print this Document to a FILE stream.
*
*/
virtual void Print( FILE* cfile, int depth = 0 ) const;
/**
* \brief
*
*/
void SetError( int err, const char* errorLocation, XmlParsingData* prevData, XmlEncoding encoding );
/**
* \brief
*
*/
virtual const XmlDocument* ToDocument() const;
/**
* \brief
*
*/
virtual XmlDocument* ToDocument() ;
/**
* \brief Walk the XML tree visiting this node and all of its children.
*
*/
virtual bool Accept( XmlVisitor* content ) const;
protected :
/**
* \brief
*
*/
virtual XmlNode* Clone() const;
/**
* \brief
*
*/
virtual void StreamIn( std::istream * in, std::string * tag );
private:
/**
* \brief
*
*/
void CopyTo( XmlDocument* target ) const;
bool error;
int errorId;
std::string errorDesc;
int tabsize;
XmlCursor errorLocation;
bool useMicrosoftBOM; // the UTF-8 BOM were found when read. Note this, and try to write.
};
/**
A XmlHandle is a class that wraps a node pointer with null checks; this is
an incredibly useful thing. Note that XmlHandle is not part of the nyXml
DOM structure. It is a separate utility class.
Take an example:
@verbatim
<Document>
<Element attributeA = "valueA">
<Child attributeB = "value1" />
<Child attributeB = "value2" />
</Element>
<Document>
@endverbatim
Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very
easy to write a *lot* of code that looks like:
@verbatim
XmlElement* root = document.FirstChildElement( "Document" );
if ( root )
{
XmlElement* element = root->FirstChildElement( "Element" );
if ( element )
{
XmlElement* child = element->FirstChildElement( "Child" );
if ( child )
{
XmlElement* child2 = child->NextSiblingElement( "Child" );
if ( child2 )
{
// Finally do something useful.
@endverbatim
And that doesn't even cover "else" cases. XmlHandle addresses the verbosity
of such code. A XmlHandle checks for null pointers so it is perfectly safe
and correct to use:
@verbatim
XmlHandle docHandle( &document );
XmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).ToElement();
if ( child2 )
{
// do something useful
@endverbatim
Which is MUCH more concise and useful.
It is also safe to copy handles - internally they are nothing more than node pointers.
@verbatim
XmlHandle handleCopy = handle;
@endverbatim
What they should not be used for is iteration:
@verbatim
int i=0;
while ( true )
{
XmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).ToElement();
if ( !child )
break;
// do something
++i;
}
@endverbatim
It seems reasonable, but it is in fact two embedded while loops. The Child method is
a linear walk to find the element, so this code would iterate much more than it needs
to. Instead, prefer:
@verbatim
XmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).ToElement();
for( child; child; child=child->NextSiblingElement() )
{
// do something
}
@endverbatim
*/
class XmlHandle{
public:
/// Create a handle from any node (at any depth of the tree.) This can be a null pointer.
XmlHandle( XmlNode* _node ) ;
/// Copy constructor
XmlHandle( const XmlHandle& ref ) ;
XmlHandle operator=( const XmlHandle& ref );
/// Return a handle to the first child node.
XmlHandle FirstChild() const;
/// Return a handle to the first child node with the given name.
XmlHandle FirstChild( const char * value ) const;
/// Return a handle to the first child element.
XmlHandle FirstChildElement() const;
/// Return a handle to the first child element with the given name.
XmlHandle FirstChildElement( const char * value ) const;
/** Return a handle to the "index" child with the given name.
The first child is 0, the second 1, etc.
*/
XmlHandle Child( const char* value, int index ) const;
/** Return a handle to the "index" child.
The first child is 0, the second 1, etc.
*/
XmlHandle Child( int index ) const;
/** Return a handle to the "index" child element with the given name.
The first child element is 0, the second 1, etc. Note that only XmlElements
are indexed: other types are not counted.
*/
XmlHandle ChildElement( const char* value, int index ) const;
/** Return a handle to the "index" child element.
The first child element is 0, the second 1, etc. Note that only XmlElements
are indexed: other types are not counted.
*/
XmlHandle ChildElement( int index ) const;
/**
* \brief
*
*/
XmlHandle FirstChild( const std::string& _value ) const;
/**
* \brief
*
*/
XmlHandle FirstChildElement( const std::string& _value ) const;
/**
* \brief
*
*/
XmlHandle Child( const std::string& _value, int index ) const ;
/**
* \brief
*
*/
XmlHandle ChildElement( const std::string& _value, int index ) const ;
/** Return the handle as a XmlNode. This may return null.
*/
XmlNode* ToNode() const ;
/** Return the handle as a XmlElement. This may return null.
*/
XmlElement* ToElement() const ;
/** Return the handle as a XmlText. This may return null.
*/
XmlText* ToText() const;
/** Return the handle as a XmlUnknown. This may return null.
*/
XmlUnknown* ToUnknown() const ;
/** @deprecated use ToNode.
Return the handle as a XmlNode. This may return null.
*/
XmlNode* Node() const;
/** @deprecated use ToElement.
Return the handle as a XmlElement. This may return null.
*/
XmlElement* Element() const ;
/** @deprecated use ToText()
Return the handle as a XmlText. This may return null.
*/
XmlText* Text() const ;
/** @deprecated use ToUnknown()
Return the handle as a XmlUnknown. This may return null.
*/
XmlUnknown* Unknown() const;
private:
XmlNode* node;
};
/** Print to memory functionality. The XmlPrinter is useful when you need to:
-# Print to memory (especially in non-STL mode)
-# Control formatting (line endings, etc.)
When constructed, the XmlPrinter is in its default "pretty printing" mode.
Before calling Accept() you can call methods to control the printing
of the XML document. After XmlNode::Accept() is called, the printed document can
be accessed via the CStr(), Str(), and Size() methods.
XmlPrinter uses the Visitor API.
@verbatim
XmlPrinter printer;
printer.SetIndent( "\t" );
doc.Accept( &printer );
fprintf( stdout, "%s", printer.CStr() );
@endverbatim
*/
class XmlPrinter : public XmlVisitor
{
public:
/**
* \brief
*
*/
XmlPrinter();
/**
* \brief
*
*/
virtual bool VisitEnter( const XmlDocument& doc );
/**
* \brief
*
*/
virtual bool VisitExit( const XmlDocument& doc );
/**
* \brief
*
*/
virtual bool VisitEnter( const XmlElement& element, const XmlAttribute* firstAttribute );
/**
* \brief
*
*/
virtual bool VisitExit( const XmlElement& element );
/**
* \brief
*
*/
virtual bool Visit( const XmlDeclaration& declaration );
/**
* \brief
*
*/
virtual bool Visit( const XmlText& text );
/**
* \brief
*
*/
virtual bool Visit( const XmlComment& comment );
/**
* \brief
*
*/
virtual bool Visit( const XmlUnknown& unknown );
/** Set the indent characters for printing. By default 4 spaces
but tab (\t) is also useful, or null/empty string for no indentation.
*/
void SetIndent( const char* _indent );
/// Query the indention string.
const char* Indent();
/** Set the line breaking string. By default set to newline (\n).
Some operating systems prefer other characters, or can be
set to the null/empty string for no indenation.
*/
void SetLineBreak( const char* _lineBreak );
/// Query the current line breaking string.
const char* LineBreak();
/** Switch over to "stream printing" which is the most dense formatting without
linebreaks. Common when the XML is needed for network transmission.
*/
void SetStreamPrinting();
/// Return the result.
const char* CStr();
/// Return the length of the result string.
size_t Size();
/// Return the result.
const std::string& Str();
private:
/**
* \brief
*
*/
void DoIndent();
/**
* \brief
*
*/
void DoLineBreak() ;
int depth;
bool simpleTextPrint;
std::string buffer;
std::string indent;
std::string lineBreak;
};
}
#ifdef _MSC_VER
#pragma warning( pop )
#endif
#endif