summaryrefslogtreecommitdiffstats
path: root/qtsoap/src/qtsoap.cpp
blob: 68ba9ae41d4f211b130b6ebdc53213ba43b37723 (plain)
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
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
// Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
// SPDX-License-Identifier: BSD-3-Clause

#include "qtsoap.h"
#include <QSet>
#include <QNetworkRequest>
#include <QNetworkReply>

/*! \page qtsoap-overview.html

    \title Qt SOAP component

    \tableofcontents

    \target overview
    \section1 Overview of the SOAP support in the QtSoap classes

    QtSoapMessage provides an interface for creating, inspecting and
    modifying SOAP messages. It has convenience functions for
    generating method requests and inspecting method response
    messages, and also functions that provide easy access to SOAP
    Fault messages.

    The QtSoapType class allows you to inspect SOAP messages with no
    knowledge of XML or DOM. Header and body items are all derived
    from QtSoapType, and through easy accessors and iterators, this
    class and its derivatives make it easy to build arrays
    (QtSoapArray), structs (QtSoapStruct) and simple types like
    String, Integer and Boolean (QtSoapSimpleType).

    Finally, QtSoapHttpTransport provides a convenient way to submit
    SOAP messages to a host via the HTTP protocol.

    \target classes
    \section1 The SOAP classes

    \table
    \header \i Class \i Short description
    \row    \i \l QtSoapMessage
	    \i Represents a SOAP message
    \row    \i \l QtSoapQName
	    \i Represents qualified names (QNames)
    \row    \i \l QtSoapType
	    \i A superclass for all data constructs in a SOAP message.
    \row    \i \l QtSoapArray
	    \i Represents a SOAP array
    \row    \i \l QtSoapArrayIterator
	    \i Lets you iterate over all the values in a SOAP array
    \row    \i \l QtSoapStruct
	    \i Represents a SOAP struct
    \row    \i \l QtSoapStructIterator
	    \i Lets you iterate over all the values in a SOAP array
    \row    \i \l QtSoapSimpleType
	    \i Represents simple SOAP types such as String, Integer and Boolean.
    \row    \i \l QtSoapHttpTransport
	    \i Provides a method for transmitting SOAP messages to an
	    HTTP server and for getting the SOAP reply.
    \endtable

    \target partial
    \section1 Status of the SOAP component

    This is a partial implementation of the SOAP v1.1 protocol.

    \list
    \i Server side SOAP is not supported.
    \i References to values (id and href attributes) are not supported.
    \i Only arrays with less than 5 dimensions are supported.
    \i Namespaces for types are not checked. Only the type names are used.
    \i The encodingStyle attribute is ignored. The serialization and
       encoding rules from section 5 in the SOAP v1.1 specification are
       assumed regardless of the value of the encodingStyle attribute.
    \i QtSoapType does not have accessors for attributes, which means
       for example that actor, mustUnderstand and so on are not
       accessible in headers.
    \i The SOAP root attribute is not supported.
    \endlist
*/

namespace {
    QString localName(const QString &tagName)
    {
	int pos;
	if ((pos = tagName.indexOf(':')))
	    return tagName.right(tagName.length() - pos - 1);

	return tagName;
    }

    QString prefix(const QString &tagName)
    {
	int pos;
	if ((pos = tagName.indexOf(':')))
	    return tagName.left(pos);

	return tagName;
    }

}

/*! \class QtSoapQName qtsoap.h

    \brief The QtSoapQName class provides a wrapper for QNames (names with
    namespaces).

    This class is used extensively in QtSoap to define and identify
    header and body elements, including method and argument names.

    The QtSoapQName consists of a name and a URI. The URI is used as
    the name's namespace, i.e. the name is qualified (hence 'Q'-Name)
    by the URI. The name() and uri() functions return the QNames's
    name and URI.

    The QtSoapQName can be empty. It can also have just a name with no
    URI. Special handling is often applied to a QtSoapQName that has
    no URI. Typically, if a QName with no namespace is used in an
    element in a SOAP document that already has a default namespace
    defined, then that namespace will be applied to the QName.

    \code
    QtSoapMessage message;

    message.setMethod(QtSoapQName("sendMessage", "http://messenging.example.com/"));
    message.addMethodArgument(QtSoapSimpleType(QtSoapQName("a"), 15));
    \endcode
*/


/*!
    Constructs a QName. Sets the QName name to \a name and the URI to
    \a uri.
*/
QtSoapQName::QtSoapQName(const QString &name, const QString &uri)
    : n(name), nuri(uri)
{
}

/*!
    Destructs the QtSoapQName.
*/
QtSoapQName::~QtSoapQName()
{
}

/*!
    Returns QName's name.
*/
QString QtSoapQName::name() const
{
    return n;
}

/*!
    Returns the QName's URI.
*/
QString QtSoapQName::uri() const
{
    return nuri;
}

/*!
    Sets the QName's name to \a s, and sets the URI to an empty string.
*/
QtSoapQName &QtSoapQName::operator =(const QString &s)
{
    n = s;
    nuri = "";

    return *this;
}

/*!
    \fn bool operator==(const QtSoapQName &s1, const QtSoapQName &s2)

    \relates QtSoapQName

    If \a s2 has a non-empty URI, this function returns true if the
    merge of the URI and the name of \a s1 is equal to that of \a s2;
    otherwise it returns false.

    If \a s2 has an empty URI, this function returns true if the name
    of \a s1 is equal to the name of \a s2; otherwise it returns false.

    The comparison is case-insensitive.
*/
bool operator ==(const QtSoapQName &s1, const QtSoapQName &s2)
{
    if (s2.uri() == "")
	return s1.name().toLower() == s2.name().toLower();

    return s1.name().toLower() == s2.name().toLower()
	  && s1.uri().toLower() == s2.uri().toLower();
}

/*!
    \fn bool operator<(const QtSoapQName &s1, const QtSoapQName &s2)

    \relates QtSoapQName

    If \a s2 has a non-empty URI, this function returns true if the
    merge of the URI and the name of \a s1 is lexically less than that
    of \a s2; otherwise it returns false.

    If \a s2 has an empty URI, this function returns true if the name
    of \a s1 is lexically less than the name of \a s2; otherwise
    it returns false.

    The comparison is case-insensitive.
*/
bool operator <(const QtSoapQName &s1, const QtSoapQName &s2)
{
    if (s2.uri() == "")
	return s1.name().toLower() < s2.name().toLower();

    return (s1.uri().toLower()+s1.name().toLower()) < (s2.uri().toLower()+s2.name().toLower());
}

/*! \class QtSoapType qtsoap.h
    \brief The QtSoapType class is the base class for all SOAP types
    in QtSoap.

    Although it is not used to create data types, a QtSoapType
    reference can be conveniently used to inspect a tree of QtSoapType
    subclasses. Accessors from this base class, such as operator[](),
    allow safe navigation.

    \code
    const QtSoapType &root = message.returnValue();
    if (root["fault"].isValid()) {
	qWarning("Warning: %s", root["fault"]["faultstring"].toString().toLatin1().constData());
    }
    \endcode

    This class holds the name(), type(), id() and href() of all its
    derived types.

    If a QtSoapType reference or pointer points to a QtSoapStruct, a
    QtSoapArray or a QtSoapSimpleType, isValid() returns true.

    \sa QtSoapStruct, QtSoapArray, QtSoapSimpleType
*/

/*!
    \class QtSoapStruct qtsoap.h
    \brief The QtSoapStruct class is an implementation of the SOAP
    struct type.

    A SOAP struct is a dictionary of QtSoapTypes where entries are
    looked up by name. Entries in a struct can be of any QtSoapType
    type, such as QtSoapArray, QtSoapStruct or QtSoapSimpleType.

    The struct can be created in several ways. parse() generates a
    struct by analyzing a QDomNode. insert() is used to add items
    manually.

    \code
    QtSoapStruct myStruct(QtSoapQName("myStruct"));

    myStruct.insert(new QtSoapSimpleType(QtSoapQName("item1"), 5));
    myStruct.insert(new QtSoapSimpleType(QtSoapQName("item2"), "hello"));
    myStruct.insert(new QtSoapSimpleType(QtSoapQName("item3"), true));
    \endcode

    Use the operator[]() or at() when looking up entries in a struct
    by name. If the names are unknown, QtSoapStructIterator lets you
    iterate through all the items.

    \code
    QtSoapType &helloItem = myStruct["Hello"];
    \endcode

    toDomElement() converts the QtSoapStruct to a DomElement.

    \sa QtSoapStructIterator, QtSoapType, QtSoapArray, QtSoapSimpleType
*/

/*! \class QtSoapStructIterator
    \brief The QtSoapStructIterator class provides an iterator for
    traversing the items in a QtSoapStruct.

    The iterator is created by passing a QtSoapStruct to the
    constructor. It it not defined which item the iterator initially
    will point to. Neither is the order in which the items are
    processed.

    key() returns the name of the current item. data() and current()
    return a pointer to the current item, or 0 if there is none.
    operator++() navigates to the next item in the struct.

    \code
    for (QtSoapStructIterator it(myStruct); it.current(); ++it) {
	QtSoapType *item = it.data();
	// process item
    }
    \endcode

    \sa QtSoapArrayIterator
*/

/*! \class QtSoapArray qtsoap.h
    \brief The QtSoapArray class is an implementation of the SOAP
    array type.

    A SOAP array is a sequence of QtSoapType objects such as
    QtSoapArrays, QtSoapStructs or QtSoapSimpleTypes, and they are
    accessible through their ordinal position. An array can be
    consecutive (0, 1, 2, 3, ...) or sparse (1, 5, 6, 10, ...) and
    they can be multidimensional ((0, 0), (0, 1), ...). QtSoapArray
    supports arrays of up to 5 dimensions. The size and dimensions of
    the array are set in the constructor. The default constructor
    produces a one dimensional array, with an unset size, meaning that
    the array can grow as required.

    All elements in a SOAP array must be of the same type. Inserting
    different types will result in a run time error.

    The parse() function builds the array by analyzing a QDomNode from
    a SOAP document. count() returns the number of items in the array.

    Retrieve items in the array with at() or operator[](). Note that
    operator[]() only works with one dimensional arrays, but there are
    at() functions for arrays of up to 5 dimensions.
    QtSoapArrayIterator lets you iterate through all items in an
    array.

    Use insert() or append() to insert items into an array manually.
    append() only works with one dimensional arrays.

    toDomElement() returns a QDomElement representation of the SOAP
    array.

    \code
    QtSoapArray array;

    array.insert(0, new QtSoapSimpleType(QtSoapQName("Peter"), "peter"));
    array.insert(1, new QtSoapSimpleType(QtSoapQName("Lisa"), "lisa"));
    array.insert(2, new QtSoapSimpleType(QtSoapQName("Paul"), "paul"));
    array.insert(3, new QtSoapSimpleType(QtSoapQName("Heather"), "heather"));
    \endcode

    \sa QtSoapType, QtSoapStruct, QtSoapSimpleType
*/

/*! \class QtSoapArrayIterator qtsoap.h
    \brief The QtSoapArrayIterator class provides an iterator for
    traversing the items in a QtSoapArray.

    The items are traversed in ascending order of index position,
    depth first.

    \code
    // Construct a 2x2 array of Strings.
    QtSoapArray array("Array of strings", String, 2, 2);
    array.insert(0, 0, new QtSoapSimpleType(Q4SoapQName("top left"), "top left");
    array.insert(0, 1, new QtSoapSimpleType(Q4SoapQName("top right"), "top right");
    array.insert(1, 0, new QtSoapSimpleType(Q4SoapQName("bottom left"), "bottom left");
    array.insert(1, 1, new QtSoapSimpleType(Q4SoapQName("bottom right"), "bottom right");

    // Traverse all items.
    QtSoapArrayIterator it(array);
    while (!it.current()) {

      // Find the position of the current element.
      int pos1, pos2;
      it.pos(&pos1, &pos2);

      qDebug() << "Position (" << pos1 << ", " << pos2 << ") is "
               << "the " << it.current()->toString() << " coordinate of the grid." << endl;

      ++it;
    }
    \endcode
*/

/*! \class QtSoapSimpleType qtsoap.h
    \brief The QtSoapSimpleType class provides a container for all
    simple SOAP types, such as strings, integers and booleans.



    \sa QtSoapType, QtSoapStruct, QtSoapArray
*/

/*! \enum QtSoapType::Type

    SOAP supports the types described in XML Schema Part 2: Datatypes
    listed at \l http://www.w3.org/TR/xmlschema-2/. The following
    values are represented using QtSoapSimpleType, except where noted.

    \value AnyURI
    \value Array Represented by QtSoapArray
    \value Base64Binary
    \value Boolean
    \value Byte
    \value Date
    \value DateTime
    \value Decimal
    \value Double
    \value Duration
    \value ENTITY
    \value Float
    \value GDay
    \value GMonth
    \value GMonthDay
    \value GYear
    \value GYearMonth
    \value HexBinary
    \value ID
    \value IDREF
    \value Int
    \value Integer
    \value Language
    \value Long
    \value NCName
    \value NMTOKEN
    \value NOTATION
    \value Name
    \value NegativeInteger
    \value NonNegativeInteger
    \value NonPositiveInteger
    \value NormalizedString
    \value Other
    \value PositiveInteger
    \value QName
    \value Short
    \value String
    \value Struct Represented by QtSoapStruct
    \value Time
    \value Token
    \value UnsignedByte
    \value UnsignedInt
    \value UnsignedLong
    \value UnsignedShort
*/

/*!
    Constructs a QtSoapType.
*/
QtSoapType::QtSoapType()
{
    t = Other;
    errorStr = "Unknown error";
}

/*!
    Constructs a QtSoapType whose name is \a name and type is \a type.
    This contructor is usually only called by constructors in
    subclasses.
*/
QtSoapType::QtSoapType(const QtSoapQName &name, Type type)
    : t(type), n(name)
{
    errorStr = "Unknown error";
}

/*!
    Creates a QtSoapType copy of \a copy.
*/
QtSoapType::QtSoapType(const QtSoapType &copy)
    : t(copy.t), errorStr(copy.errorStr), i(copy.i),
      n(copy.n), u(copy.u), h(copy.h)
{
}

/*!
    Destructs a QtSoapType.
*/
QtSoapType::~QtSoapType()
{
}

/*!
    Clears any contents. In this base implementation, clear() does
    nothing.
*/
void QtSoapType::clear()
{
}

/*!
    Makes this QtSoapType equal to \a copy.
*/
QtSoapType &QtSoapType::operator =(const QtSoapType &copy)
{
    t = copy.t;
    errorStr = copy.errorStr;
    i = copy.i;
    n = copy.n;
    u = copy.u;
    h = copy.h;
    return *this;
}

/*!
    Returns true if this object is of type QtSoapStruct, QtSoapArray
    or QtSoapSimpletype; otherwise returns false.
*/
bool QtSoapType::isValid() const
{
    return false;
}

/*!
    Returns the QString equivalent of type \a t.
*/
QString QtSoapType::typeToName(QtSoapType::Type t)
{
    switch (t) {
    case Duration: return "duration";
    case DateTime: return "dateTime";
    case Time: return "time";
    case Date: return "date";
    case GYearMonth: return "gYearMonth";
    case GYear: return "gYear";
    case GMonthDay: return "gMonthDay";
    case GDay: return "gDay";
    case GMonth: return "gMonth";
    case Boolean: return "boolean";
    case Base64Binary: return "base64Binary";
    case HexBinary: return "hexBinary";
    case Float: return "float";
    case Double: return "double";
    case AnyURI: return "anyURI";
    case QName: return "QName";
    case NOTATION: return "NOTATION";
    case String: return "string";
    case NormalizedString: return "normalizedString";
    case Token: return "token";
    case Language: return "language";
    case Name: return "name";
    case NMTOKEN: return "NMToken";
    case NCName: return "NCName";
    case ID: return "ID";
    case IDREF: return "IDREF";
    case ENTITY: return "ENTITY";
    case Decimal: return "decimal";
    case Integer: return "integer";
    case NonPositiveInteger: return "nonPositiveInteger";
    case NegativeInteger: return "negativeInteger";
    case Long: return "long";
    case Int: return "int";
    case Short: return "short";
    case Byte: return "byte";
    case NonNegativeInteger: return "nonNegativeInteger";
    case UnsignedLong: return "unsignedLong";
    case PositiveInteger: return "positiveInteger";
    case UnsignedInt: return "unsignedInt";
    case UnsignedShort: return "unsignedShort";
    case UnsignedByte: return "unsignedByte";
    case Array: return "array";
    case Struct: return "struct";
    default: return "other";
    }
}

/*!
    Returns the QtSoapType::Type called \a name.
*/
QtSoapType::Type QtSoapType::nameToType(const QString &name)
{
    const QString type = name.trimmed().toLower();

    if (type == "string")
	return String;
    else if (type == "normalizedstring")
	return NormalizedString;
    else if (type == "token")
	return Token;
    else if (type == "language")
	return Language;
    else if (type == "name")
	return Name;
    else if (type == "ncname")
	return NCName;
    else if (type == "nmtoken")
	return NMTOKEN;
    else if (type == "id")
	return ID;
    else if (type == "idref")
	return IDREF;
    else if (type == "entity")
	return ENTITY;
    else if (type == "base64binary")
	return Base64Binary;
    else if (type == "hexBinary")
	return HexBinary;
    else if (type == "anyuri")
	return AnyURI;
    else if (type == "qname")
	return QName;
    else if (type == "notation")
	return NOTATION;
    else if (type == "duration")
	return Duration;
    else if (type == "datetime")
	return DateTime;
    else if (type == "time")
	return Time;
    else if (type == "date")
	return Date;
    else if (type == "gyearmonth")
	return GYearMonth;
    else if (type == "gyear")
	return GYear;
    else if (type == "gmonthday")
	return GMonthDay;
    else if (type == "gday")
	return GDay;
    else if (type == "gmonth")
	return GMonth;
    else if (type == "decimal")
	return Decimal;
    else if (type == "integer")
	return Integer;
    else if (type == "nonPositiveinteger")
	return NonPositiveInteger;
    else if (type == "negativeinteger")
	return NegativeInteger;
    else if (type == "long")
	return Long;
    else if (type == "int")
	return Int;
    else if (type == "short")
	return Short;
    else if (type == "byte")
	return Byte;
    else if (type == "nonnegativeinteger")
	return NonNegativeInteger;
    else if (type == "unsignedlong")
	return UnsignedLong;
    else if (type == "unsignedint")
	return UnsignedInt;
    else if (type == "unsignedshort")
	return UnsignedShort;
    else if (type == "unsignedbyte")
	return UnsignedByte;
    else if (type == "positiveinteger")
	return PositiveInteger;
    else if (type == "float")
	return Float;
    else if (type == "double")
	return Double;
    else if (type == "boolean")
	return Boolean;
    else
	return Other;
}

/*!
    Returns QString::null.
*/
QString QtSoapType::toString() const
{
    return QString::null;
}

/*!
    Returns 0.
*/
int QtSoapType::toInt() const
{
    return 0;
}

/*!
    Returns false.
*/
bool QtSoapType::toBool() const
{
    return false;
}

/*!
    Returns the QDomElement representation of this QtSoapType
    as a child of \a document.
*/
QDomElement QtSoapType::toDomElement(QDomDocument document) const
{
    Q_UNUSED(document);
    return QDomElement();
}

/*!
    Returns the QString representation of this QtSoapType's type.
*/
QString QtSoapType::typeName() const
{
    return QtSoapType::typeToName(type());
}

/*!
    Returns the type as a QtSoapType::Type.
*/
QtSoapType::Type QtSoapType::type() const
{
    return t;
}

/*!
    Returns the QName (qualified name) of this QtSoapType.
*/
QtSoapQName QtSoapType::name() const
{
    return n;
}

/*!
    Returns the ID of this QtSoapType.
*/
QString QtSoapType::id() const
{
    return i;
}

/*!
    Returns the href attribute of this QtSoapType.
*/
QString QtSoapType::href() const
{
    return h;
}

/*!
    Sets the QName (qualified name) of this QtSoapType to \a name.
*/
void QtSoapType::setName(const QtSoapQName &name)
{
    this->n = name;
}

/*!
    Sets the ID of this QtSoapType to \a i.
*/
void QtSoapType::setId(const QString &i)
{
    this->i = i;
}

/*!
    Sets the href attribute of this QtSoapType to \a h.
*/
void QtSoapType::setHref(const QString &h)
{
    this->h = h;
}

/*!
    Returns the value of this QtSoapType. In the base implementation,
    an invalid QVariant() is returned.
*/
QVariant QtSoapType::value() const
{
    return QVariant();
}

/*!
    Returns a human readable explanation of the most recent error.
*/
QString QtSoapType::errorString() const
{
    return errorStr;
}

/*!
    Returns the number of child items in this QtSoapType. In the base
    implementation, this returns 0.
*/
int QtSoapType::count() const
{
    return 0;
}

/*!
    Returns a reference to the child item at ordinal position \a pos.
    If no item exists at this position, returns an empty QtSoapType.
*/
QtSoapType &QtSoapType::operator [](int /* pos */ )
{
    static QtSoapType NIL;
    return NIL;
}

/*!
    \overload

    Returns a reference to the child item whose QName (qualified name)
    is \a key. If no item exists with this key an empty QtSoapType is
    returned.
*/
QtSoapType &QtSoapType::operator [](const QtSoapQName & /* key */)
{
    static QtSoapType NIL;
    return NIL;
}

/*!
    \overload

    Returns a reference to the child item whose QName (qualified name)
    is \a key, regardless of the qualified name's URI. If no item
    exists with this key, an empty QtSoapType is returned.
*/
QtSoapType &QtSoapType::operator [](const QString & /* key */)
{
    static QtSoapType NIL;
    return NIL;
}

/*!
    \overload

    Returns a reference to the child item at ordinal position \a pos.
    If no item exists at this position, returns an empty QtSoapType.
*/
const QtSoapType &QtSoapType::operator [](int /* pos */) const
{
    static QtSoapType NIL;
    return NIL;
}

/*!
    \overload

    Returns a reference to the child item whose QName (qualified name)
    is \a key. If no item exists with this key, returns an empty
    QtSoapType.
*/
const QtSoapType &QtSoapType::operator [](const QtSoapQName & /* key */) const
{
    static QtSoapType NIL;
    return NIL;
}

/*!
    \overload

    Returns a reference to the child item whose QName (qualified name)
    is \a key, regardless of the qualified name's URI. If no item
    exists with this key, returns an empty QtSoapType.
*/
const QtSoapType &QtSoapType::operator [](const QString & /* key */) const
{
    static QtSoapType NIL;
    return NIL;
}

/*!
    Attempts to interpret \a node as a QtSoapType, and returns true if
    successful. This base implementation always returns false.
*/
bool QtSoapType::parse(QDomNode /* node */)
{
    return false;
}

/*!
    \overload

    Constructs an empty one dimensional QtSoapArray whose element type
    is undefined. The first insert will decide what type of elements
    the array can contain.
*/
QtSoapArray::QtSoapArray()
    : QtSoapType(QtSoapQName(), Array), arrayType(Other), order(1)
{
    lastIndex = 0;
    siz0 = 0;
    siz1 = 0;
    siz2 = 0;
    siz3 = 0;
    siz4 = 0;
}

/*!
    Constructs an empty QtSoapArray whose QName (qualified name) is \a
    name, that contains elements of type \a type, and whose dimensions
    are given by \a size0, \a size1, \a size2, \a size3 and \a size4.

    To construct a one dimensional array of size 5, set \a size0 = 5. To
    create a two dimensional array of size 5x10, set \a size0 = 5 and \a
    size1 = 10. The maximum dimension of a QtSoapArray is 5.
*/
QtSoapArray::QtSoapArray(const QtSoapQName &name, QtSoapType::Type type, int size0,
			 int size1, int size2, int size3, int size4)
    : QtSoapType(name, Array), lastIndex(0), arrayType(type),
      siz0(size0), siz1(size1), siz2(size2), siz3(size3),
      siz4(size4)
{
    if (size4 != -1) order = 5;
    else if (size3 != -1) order = 4;
    else if (size2 != -1) order = 3;
    else if (size1 != -1) order = 2;
    else order = 1;
}

/*!
    Create a QtSoapArray that is a copy of \a copy.
*/
QtSoapArray::QtSoapArray(const QtSoapArray &copy)
    : QtSoapType(copy)
{
    *this = copy;
}

/*!
    Destructs the QtSoapArray.
*/
QtSoapArray::~QtSoapArray()
{
}

/*!
    Clears the contents, and the dimensions of the QtSoapArray.
*/
void QtSoapArray::clear()
{
    array.clear();
    lastIndex = 0;
    arrayType = Other;
    siz0 = siz1 = siz2 = siz3 = siz4 = 0;
    order = -1;
}

/*!
    Makes this QtSoapArray a copy of \a copy.
*/
QtSoapArray &QtSoapArray::operator = (const QtSoapArray &copy)
{
    if (this == &copy)
        return *this;
    t = copy.t;
    errorStr = copy.errorStr;
    i = copy.i;
    n = copy.n;
    u = copy.u;
    h = copy.h;
    lastIndex = copy.lastIndex;
    order = copy.order;
    siz0 = copy.siz0;
    siz1 = copy.siz1;
    siz2 = copy.siz2;
    siz3 = copy.siz3;
    siz4 = copy.siz4;
    array = copy.array;

    return *this;
}

/*!
    Appends the QtSoapType \a item to the end of this array, which must
    be one dimensional.

    \sa insert()
*/
void QtSoapArray::append(QtSoapType *item)
{
    if (order != 1) {
	qWarning("Attempted to insert item at position (%i) in %i-dimensional QtSoapArray.",
		 lastIndex, order);
	return;
    }

    if (array.count() == 0) {
	array.insert(0, item);
    } else {
	array.insert(lastIndex + 1, item);
	++lastIndex;
    }
}

/*!
    Inserts the QtSoapType \a item at the absolute position \a pos in
    the array. Note that this function can be used to insert items
    into arrays with any number of dimensions.

    If the array is one dimensional, then \a pos is simply the index
    position in the array. But if the array is multi-dimensional then
    \a pos is the absolute position. For example, if we have a two
    dimensional array [['a', 'b'], ['c', 'd'], ['e', 'f']], the
    element at position 0 is 'a', at position 1 is 'b', at position 2
    is 'c', and so on. (There are other insert() overloads that allow
    for each dimension to be specified individually.)
*/
void QtSoapArray::insert(int pos, QtSoapType *item)
{
    if (arrayType == Other)
	arrayType = item->type();

    if (item->type() != arrayType) {
	qWarning("Attempted to insert item of type \"%s\" in QtSoapArray of type \"%s\".",
		 item->typeName().toLatin1().constData(), QtSoapType::typeToName(arrayType).toLatin1().constData());
	return;
    }

    if (order == -1)
	order = 1;
    else if (order == 1 && pos > lastIndex)
	lastIndex = pos;

    array.insert(pos, item);
}

/*!
    \overload

    Insert the QtoSoapType \a item at position \a pos0 x \a pos1 in a
    two dimensional array.
*/
void QtSoapArray::insert(int pos0, int pos1, QtSoapType *item)
{
    if (order != 2) {
	qWarning("Attempted to insert item at position (%i, %i)"
		 " in %i-dimensional QtSoapArray.",
		 pos0, pos1, order);
	return;
    }

    if (pos0 < 0 || pos0 >= siz0 || pos1 < 0 || pos1 >= siz1) {
	qWarning("Attempted to insert item at position (%i, %i)"
		 " when range of QtSoapArray is (0..%i, 0..%i)",
		 pos0, pos1, siz0 - 1, siz1 - 1);
	return;
    }

    insert((pos0 * siz1) + pos1, item);
}

/*!
    \overload

    Insert the QtoSoapType \a item at position \a pos0 x \a pos1 x \a
    pos2 in a three dimensional array.
*/
void QtSoapArray::insert(int pos0, int pos1, int pos2, QtSoapType *item)
{
    if (order != 3) {
	qWarning("Attempted to insert item at position (%i, %i, %i)"
		 " in %i-dimensional QtSoapArray.",
		 pos0, pos1, pos2, order);
	return;
    }

    if (pos0 < 0 || pos0 >= siz0 || pos1 < 0 || pos1 >= siz1 || pos2 < 0 || pos2 >= siz2) {
	qWarning("Attempted to insert item at position (%i, %i, %i)"
		 " when range of QtSoapArray is (0..%i, 0..%i, 0..%i)",
		 pos0, pos1, pos2, siz0 - 1, siz1 - 1, siz2 - 1);
	return;
    }

    insert((pos0 * siz2 * siz1) + (pos1 * siz2) + pos2, item);
}

/*!
    \overload

    Insert the QtoSoapType \a item at position \a pos0 x \a pos1 x \a
    pos2 x \a pos3 in a four dimensional array.
*/
void QtSoapArray::insert(int pos0, int pos1, int pos2, int pos3, QtSoapType *item)
{
    if (order != 4) {
	qWarning("Attempted to insert item at position (%i, %i, %i, %i)"
		 " in %i-dimensional QtSoapArray.",
		 pos0, pos1, pos2, pos3, order);
	return;
    }

    insert((pos0 * siz3 * siz2 * siz1)
	   + (pos1 * siz3 * siz2)
	   + (pos2 * siz3)
	   + pos3,
	   item);
}

/*!
    \overload

    Insert the QtoSoapType \a item at position \a pos0 x \a pos1 x \a
    pos2 x \a pos3 x \a pos4 in a five dimensional array.
*/
void QtSoapArray::insert(int pos0, int pos1, int pos2, int pos3, int pos4,
			 QtSoapType *item)
{
    if (order != 5) {
	qWarning("Attempted to insert item at position (%i, %i, %i, %i, %i)"
		 " in %i-dimensional QtSoapArray.",
		 pos0, pos1, pos2, pos3, pos4, order);
	return;
    }

    insert((pos0 * siz4 * siz3 * siz2 * siz1)
	   + (pos1 * siz4 * siz3 * siz2)
	   + (pos2 * siz4 * siz3)
	   + (pos3 * siz4)
	   + pos4,
	   item);
}

/*! \internal

    Given the size and dimensions of the array, generates a string
    used to represent the array in XML. For example, a 1-dimensional
    array of size 5 would get [5], a 2-dimensional array of size 5x10
    would get [5,10].
*/
QString QtSoapArray::arraySizeString() const
{
    QString arraySize = "[";
    if (siz0 != -1) {
	arraySize += QString::number(siz0);
	if (order > 1) arraySize += "," + QString::number(siz1);
	if (order > 2) arraySize += "," + QString::number(siz2);
	if (order > 3) arraySize += "," + QString::number(siz3);
	if (order > 4) arraySize += "," + QString::number(siz4);
    }

    arraySize += "]";
    return arraySize;
}

/*! \internal

    Recursively inspects the items and any child arrays' items to
    generate the aggregate type of items in this array. It the array
    contains ints, returns "int[5]", but if the array is of arrays of
    arrays of ints, the function returns "int[][][5]".
*/
QString QtSoapArray::arrayTypeString() const
{
    if (arrayType != Array)
	return QtSoapType::typeToName(arrayType);

    QString atString;
    QtSoapArray *ar = const_cast<QtSoapArray *>(this);
    do {
	if (ar->count()	== 0)
	    break;

	atString += ar->arraySizeString();

	QtSoapArrayIterator it(*const_cast<QtSoapArray *>(this));
	if (it.data()->type() != Array)
	    break;

	ar = (QtSoapArray *)it.data();
    } while (ar);


    QtSoapArrayIterator it(*const_cast<QtSoapArray *>(this));
    if (ar->count() == 0)
	atString = QtSoapSimpleType::typeToName(Int) + atString;
    else
	atString = it.data()->typeName() + atString;

    return atString;
}

/*!
    Returns the QDomElement representation of this QtSoapArray. The
    returned QDomElement is created using \a doc.
*/
QDomElement QtSoapArray::toDomElement(QDomDocument doc) const
{
    QString prefix = QtSoapNamespaces::instance().prefixFor(n.uri());
    QDomElement a = n.uri() == ""
		    ? doc.createElement( n.name())
		    : doc.createElementNS(n.uri(), prefix + ":" + n.name());

    QString schemaprefix = QtSoapNamespaces::instance().prefixFor(XML_SCHEMA_INSTANCE);
    a.setAttributeNS(XML_SCHEMA_INSTANCE, schemaprefix + ":type", "xsd:Array");

    QString encprefix = QtSoapNamespaces::instance().prefixFor(SOAPv11_ENCODING);
    a.setAttributeNS(SOAPv11_ENCODING, encprefix + ":arrayType", "xsd:" + arrayTypeString());

    for (QtSoapArrayIterator i(*const_cast<QtSoapArray *>(this)); !i.atEnd(); ++i) {
	QDomElement item = i.data()->toDomElement(doc);
	item.setTagName("item");

	int pos0, pos1, pos2, pos3, pos4;
	i.pos(&pos0, &pos1, &pos2, &pos3, &pos4);

	QString position = "[" + QString::number(pos0);
	if (order > 1) position += "," + QString::number(pos1);
	if (order > 2) position += "," + QString::number(pos2);
	if (order > 3) position += "," + QString::number(pos3);
	if (order > 4) position += "," + QString::number(pos4);
	position += "]";

	QString envprefix = QtSoapNamespaces::instance().prefixFor(SOAPv11_ENVELOPE);
	item.setAttributeNS(SOAPv11_ENVELOPE, envprefix + ":position", position);
	a.appendChild(item);
    }

    return a;
}

/*! \reimp

    For this class, always returns true.
*/
bool QtSoapArray::isValid() const
{
    return true;
}

/*!
    Inspects \a node and builds the content of the QtSoapArray if \a
    node qualifies as a SOAP array. Returns true if it does; otherwise
    returns false.
*/
bool QtSoapArray::parse(QDomNode node)
{
    if (node.isNull() || !node.isElement())
	return false;

    QDomElement e = node.toElement();
    QDomAttr typeattr = e.attributeNode("type");
    if (!typeattr.isNull() && (localName(typeattr.value()).toLower() != "array"))
	return false;


    QDomNodeList children = e.childNodes();
    int c = children.count();
    array.clear();
    // ### array.resize(c);

    int pos = 0;
    for (int i = 0; i < c; ++i) {
	QDomNode n = children.item(i);
        if (n.isComment())
            continue;
	if (!n.isElement()){
	    // ### An error in the soap document.
	    return false;
	}

	QDomElement elem = n.toElement();

	QtSmartPtr<QtSoapType> type = QtSoapTypeFactory::instance().soapType(elem);
	if (!type.ptr()) {
	    // ### An error in the soap document.
	    return false;
	}

	// ### Check namespace
	QDomAttr posattr = elem.attributeNode("position");
	if (!posattr.isNull())
	    pos = posattr.value().toInt();

	array.insert(pos, type);
	++pos;
    }

    setName(QtSoapQName(localName(e.tagName()), e.namespaceURI()));
    return true;
}

/*!
    Returns the number of items in the array. Note that this is not
    the same as the size of the array, because the array may be sparse.
*/
int QtSoapArray::count() const
{
    return array.count();
}

/*!
    Returns a reference to the item at ordinal position \a pos. If
    there is no item at position \a pos, returns an empty QtSoapType.
*/
QtSoapType &QtSoapArray::operator [](int pos)
{
    return at(pos);
}

/*!
    \overload

    Returns a reference to the child item whose local name is \a s. If
    there is no item with this local name, returns an empty
    QtSoapType.
*/
QtSoapType &QtSoapArray::operator [](const QString &s)
{
    return QtSoapType::operator[](s);
}

/*!
    \overload

    Returns a reference to the child item whose QName (qualified name)
    is \a s. If there is no item with this name, returns an empty
    QtSoapType.
*/
QtSoapType &QtSoapArray::operator [](const QtSoapQName &s)
{
    return QtSoapType::operator[](s);
}

/*!
    \overload

    Returns a reference to the item at ordinal position \a pos. If
    there is no item at position \a pos, returns an empty QtSoapType.
*/
const QtSoapType &QtSoapArray::operator [] (int pos) const
{
    return at(pos);
}

/*!
    \overload

    Returns a reference to the child item whose local name is \a s. If
    there is no item with this local name, returns an empty
    QtSoapType.
*/
const QtSoapType &QtSoapArray::operator [](const QString &s) const
{
    return QtSoapType::operator[](s);
}

/*!
    \overload

    Returns a reference to the child item whose QName (qualified name)
    is \a s. If there is no item with this name, returns an empty
    QtSoapType.
*/
const QtSoapType &QtSoapArray::operator [](const QtSoapQName &s) const
{
    return QtSoapType::operator[](s);
}

/*!
    Returns a reference to the item at ordinal position \a pos. If
    there is no item at position \a pos, returns an empty QtSoapType.
*/
QtSoapType &QtSoapArray::at(int pos)
{
    static QtSoapType NIL;

    if (array.find(pos) != array.end())
	return *array[pos];
    else
	return NIL;
}

/*!
    \overload

    Returns a reference to the item at ordinal position \a pos0 x \a
    pos1 in a two dimensional array. If there is no such item, returns
    an empty QtSoapType.
*/
QtSoapType &QtSoapArray::at(int pos0, int pos1)
{
    return at(pos0 * siz1 + pos1);
}

/*!
    \overload

    Returns a reference to the item at ordinal position \a pos0 x \a
    pos1 x \a pos2 in a three dimensional array. If there is no such
    item, returns an empty QtSoapType.
*/
QtSoapType &QtSoapArray::at(int pos0, int pos1, int pos2)
{
    return at((pos0 * siz2 * siz1) + (pos1 * siz2) + pos2);
}

/*!
    \overload

    Returns a reference to the item at ordinal position \a pos0 x \a
    pos1 x \a pos2 x \a pos3 in a four dimensional array. If there is no
    such item, returns an empty QtSoapType.
*/
QtSoapType &QtSoapArray::at(int pos0, int pos1, int pos2, int pos3)
{
    return at((pos0 * siz3 * siz2 * siz1)
	      + (pos1 * siz3 * siz2)
	      + (pos2 * siz3)
	      + pos3);
}

/*!
    \overload

    Returns a reference to the item at ordinal position \a pos0 x \a
    pos1 x \a pos2 x \a pos3 x \a pos4 in a five dimensional array. If
    there is no such item, returns an empty QtSoapType.
*/
QtSoapType &QtSoapArray::at(int pos0, int pos1, int pos2, int pos3, int pos4)
{
    return at((pos0 * siz4 * siz3 * siz2 * siz1)
	      + (pos1 * siz4 * siz3 * siz2)
	      + (pos2 * siz4 * siz3)
	      + (pos3 * siz4)
	      + pos4);
}

/*!
    \overload

    Returns a reference to the item at ordinal position \a pos. If
    there is no item at position \a pos, returns an empty QtSoapType.
*/
const QtSoapType &QtSoapArray::at(int pos) const
{
    static QtSoapType NIL;

    if (array.find(pos) != array.end())
	return *array[pos];
    else
	return NIL;
}

/*!
    \overload

    Returns a reference to the item at ordinal position \a pos0 x \a
    pos1 in a two dimensional array. If there is no such item, returns
    an empty QtSoapType.
*/
const QtSoapType &QtSoapArray::at(int pos0, int pos1) const
{
    return at(pos0 * siz1 + pos1);
}

/*!
    \overload

    Returns a reference to the item at ordinal position \a pos0 x \a
    pos1 x \a pos2 in a three dimensional array. If there is no such
    item, returns an empty QtSoapType.
*/
const QtSoapType &QtSoapArray::at(int pos0, int pos1, int pos2) const
{
    return at((pos0 * siz2 * siz1) + (pos1 * siz2) + pos2);
}

/*!
    \overload

    Returns a reference to the item at ordinal position \a pos0 x \a
    pos1 x \a pos2 x \a pos3 in a four dimensional array. If there is no
    such item, returns an empty QtSoapType.
*/
const QtSoapType &QtSoapArray::at(int pos0, int pos1, int pos2, int pos3) const
{
    return at((pos0 * siz3 * siz2 * siz1)
	      + (pos1 * siz3 * siz2)
	      + (pos2 * siz3)
	      + pos3);
}

/*!
    \overload

    Returns a reference to the item at ordinal position \a pos0 x \a
    pos1 x \a pos2 x \a pos3 x \a pos4 in a five dimensional array. If
    there is no such item, returns an empty QtSoapType.
*/
const QtSoapType &QtSoapArray::at(int pos0, int pos1, int pos2, int pos3, int pos4) const
{
    return at((pos0 * siz4 * siz3 * siz2 * siz1)
	      + (pos1 * siz4 * siz3 * siz2)
	      + (pos2 * siz4 * siz3)
	      + (pos3 * siz4)
	      + pos4);
}

/*!
    Constructs a QtSoapArrayIterator on \a array, initializing
    the iterator to point to the first element.
*/
QtSoapArrayIterator::QtSoapArrayIterator(QtSoapArray &array)
    : it(array.array.begin()), arr(&array)
{
}

/*!
    Constructs a QtSoapArrayIterator that is a copy of \a copy.
*/
QtSoapArrayIterator::QtSoapArrayIterator(const QtSoapArrayIterator &copy)
    : it(copy.it), arr(copy.arr)
{
}

/*!
    Returns false if this iterator points to an item in the array, otherwise true.
*/
bool QtSoapArrayIterator::atEnd() const
{
    return (it == arr->array.end());
}

/*!
    Assignment operator of QtSoapArrayIterator. Makes this iterator a
    copy of \a copy.
*/
QtSoapArrayIterator &QtSoapArrayIterator::operator =(const QtSoapArrayIterator &copy)
{
    it = copy.it;
    arr = copy.arr;

    return *this;
}

/*!
    Destructs the QtSoapArrayIterator.
*/
QtSoapArrayIterator::~QtSoapArrayIterator()
{
}

/*!
    \overload

    Returns the ordinal position of the iterator. Works for arrays of
    any dimension, but is only useful for one dimensional arrays.
*/
int QtSoapArrayIterator::pos() const
{
    return it.key();
}

/*!
    Populates the arguments \a pos0, \a pos1, \a pos2, \a pos3 and \a
    pos4 with the coordinate of the current position of the iterator.
    For a one dimensional array, only \a pos0 is populated. For a two
    dimensional array, \a pos0 and \a pos1 are populated, and so on.

    Any of the arguments that are 0-pointers are ignored.
*/
void QtSoapArrayIterator::pos(int *pos0, int *pos1, int *pos2,
			      int *pos3, int *pos4) const
{
    const int key = it.key();

    switch (arr->order) {
    case 1:
	if (pos0) *pos0 = key;
	break;
    case 2: {
	const int tmp = key / arr->siz1;
	if (pos0) *pos0 = tmp;
	if (pos1) *pos1 = key - (tmp * arr->siz1);
    }
	break;
    case 3: {
	const int tmp0 = key / (arr->siz2 * arr->siz1);
	const int tmp1 = key - (tmp0 * (arr->siz2 * arr->siz1));
	const int tmp2 = tmp1 / arr->siz2;
	if (pos0) *pos0 = tmp0;
	if (pos1) *pos1 = tmp2;
	if (pos2) *pos2 = tmp1 - (tmp2 * arr->siz2);
    }
	break;
    case 4: {
	const int tmp0 = key / (arr->siz3 * arr->siz2 * arr->siz1);
	const int tmp1 = key - (tmp0 * (arr->siz3 * arr->siz2 * arr->siz1));
	const int tmp2 = tmp1 / (arr->siz3 * arr->siz2);
	const int tmp3 = tmp1 - (tmp2 * (arr->siz3 * arr->siz2));
	const int tmp4 = tmp3 / arr->siz3;
	const int tmp5 = tmp3 - (tmp4 * arr->siz3);
	if (pos0) *pos0 = tmp0;
	if (pos1) *pos1 = tmp2;
	if (pos2) *pos2 = tmp4;
	if (pos3) *pos3 = tmp5;
    }
	break;
    case 5: {
	const int tmp0 = key / (arr->siz4 * arr->siz3 * arr->siz2 * arr->siz1);
	const int tmp1 = key - (tmp0 * (arr->siz4 * arr->siz3 * arr->siz2 * arr->siz1));
	const int tmp2 = tmp1 / (arr->siz4 * arr->siz3 * arr->siz2);
	const int tmp3 = tmp1 - (tmp2 * (arr->siz4 * arr->siz3 * arr->siz2));
	const int tmp4 = tmp3 / (arr->siz4 * arr->siz3);
	const int tmp5 = tmp3 - (tmp4 * arr->siz4 * arr->siz3);
	const int tmp6 = tmp5 / arr->siz3;
	const int tmp7 = tmp5 - (tmp6 * arr->siz3);
	if (pos0) *pos0 = tmp0;
	if (pos1) *pos1 = tmp2;
	if (pos2) *pos2 = tmp4;
	if (pos3) *pos3 = tmp6;
	if (pos4) *pos4 = tmp7;
    }
	break;
    default:
	break;
    }
}

/*!
    Returns a reference to the item that the iterator is currently
    pointing to.
*/
QtSoapType *QtSoapArrayIterator::data()
{
    if (it == arr->array.end())
        return 0;
    return it.value().ptr();
}

/*!
    Returns a reference to the item that the iterator is currently
    pointing to.
*/
const QtSoapType *QtSoapArrayIterator::current() const
{
    if (it == arr->array.end())
        return 0;
    return it.value().ptr();
}

/*!
    Moves the iterator position to the next item in the array.
*/
void QtSoapArrayIterator::operator ++()
{
    ++it;
}

/*!
    Returns true if this Iterator's position is not equal to
    the position of \a j; otherwise returns false.
*/
bool QtSoapArrayIterator::operator != (const QtSoapArrayIterator &j) const
{
    return it != j.it;
}

/*!
    Returns true if this Iterator's position is equal to the position
    of \a j; otherwise returns false.
*/
bool QtSoapArrayIterator::operator == (const QtSoapArrayIterator &j) const
{
    return it == j.it;
}

/*!
    Constructs an empty QtSoapStruct.
*/
QtSoapStruct::QtSoapStruct()
    : QtSoapType(QtSoapQName(), Struct)
{
}

/*!
    Constructs an empty QtSoapStruct and sets its QName (qualified
    name) to \a name.
*/
QtSoapStruct::QtSoapStruct(const QtSoapQName &name)
    : QtSoapType(name, Struct)
{
}

/*!
    Constructs a QtSoapStruct that is a copy of \a copy.
*/
QtSoapStruct::QtSoapStruct(const QtSoapStruct &copy)
    : QtSoapType(copy)
{
    *this = copy;
}

/*!
    Destructs the QtSoapStruct.
*/
QtSoapStruct::~QtSoapStruct()
{
}

/*!
    Removes all items from the struct.
*/
void QtSoapStruct::clear()
{
    dict.clear();
}

/*!
    Makes this struct a copy of \a copy.
*/
QtSoapStruct &QtSoapStruct::operator =(const QtSoapStruct &copy)
{
    if (this == &copy)
        return *this;
    t = copy.t;
    errorStr = copy.errorStr;
    i = copy.i;
    n = copy.n;
    u = copy.u;
    h = copy.h;
    i = copy.i;
    dict = copy.dict;

    return *this;
}

/*!
    Inserts the QtSoapType \a item into this struct. Any existing
    item with the same QName (qualified name) will be erased.
*/
void QtSoapStruct::insert(QtSoapType *item)
{
    dict.append(item);
}

/*!
    Generates the QDomElement representation of this struct.  The
    returned QDomElement is created using \a doc.
*/
QDomElement QtSoapStruct::toDomElement(QDomDocument doc) const
{
    QString prefix = QtSoapNamespaces::instance().prefixFor(n.uri());
    QDomElement a = n.uri() == ""
		    ? doc.createElement(n.name())
		    : doc.createElementNS(n.uri(), prefix + ":" + n.name());

    for (QtSoapStructIterator i(*const_cast<QtSoapStruct *>(this)); i.data(); ++i)
	a.appendChild(i.data()->toDomElement(doc));

    return a;
}

/*! \reimp
 */
bool QtSoapStruct::isValid() const
{
    return true;
}

/*!
    Inspects \a node and constructs the equivalent QtSoapStruct if \a
    node qualifies as a SOAP struct. Returns true if it does;
    otherwise returns false.
*/
bool QtSoapStruct::parse(QDomNode node)
{
    if (node.isNull() || !node.isElement())
	return false;

    QDomElement e = node.toElement();
    QDomNodeList children = e.childNodes();
    int c = children.count();
    dict.clear();

    for (int i = 0; i < c; ++i) {
	QDomNode n = children.item(i);
        if (n.isComment())
            continue;
	if (!n.isElement()){
	    errorStr = "In the struct element " + e.tagName();
	    errorStr += ", the " + QString::number(i) + "th child ";
	    errorStr += "is not an element.";
	    return false;
	}

	QtSmartPtr<QtSoapType> type = QtSoapTypeFactory::instance().soapType(n.toElement());
	if (!type.ptr()) {
	    errorStr = "In the struct element " + e.tagName();
	    errorStr += ", child #" + QString::number(i) + ", ";
	    errorStr += n.toElement().tagName() + ", was not recognized as a SOAP type.";
	    return false;
	}

	dict.append(type);
    }

    setName(QtSoapQName(localName(e.tagName()), e.namespaceURI()));
    return true;
}

/*!
    Returns the number of items in this struct.
*/
int QtSoapStruct::count() const
{
    return dict.count();
}

/*!
    Returns a reference to the item in this struct whose QName
    (qualified name) is \a key. If no such item exists, an empty
    QtSoapType is returned.
*/
QtSoapType &QtSoapStruct::operator [](const QtSoapQName &key)
{
    return at(key);
}

/*!
    \overload

    Returns a reference to the item in this struct whose QName
    (qualified name) is \a key. If no such item exists, an empty
    QtSoapType is returned.
*/
const QtSoapType &QtSoapStruct::operator [](const QtSoapQName &key) const
{
    return at(key);
}

/*!
    \overload

    Returns a reference to the item in this struct whose QName
    (qualified name) is \a key. If no such item exists, an empty
    QtSoapType is returned.
*/
QtSoapType &QtSoapStruct::operator [](const QString &key)
{
    return at(QtSoapQName(key, ""));
}

/*!
    \overload

    Returns a reference to the item in this struct whose QName
    (qualified name) is \a key. If no such item exists, an empty
    QtSoapType is returned.
*/
const QtSoapType &QtSoapStruct::operator [](const QString &key) const
{
    return at(QtSoapQName(key, ""));
}

/*!
    \overload

    Returns a reference to item number \a i in this struct. If no such
    item exists, an empty QtSoapType is returned.

    The items are ordered in the sequence in which they were inserted,
    starting from 0.
*/
QtSoapType &QtSoapStruct::operator [](int i)
{
    static QtSoapType NIL;
    if (i < 0 || i >= dict.count())
        return NIL;

    return *dict[i].ptr();
}

/*!
    \overload

    Returns a reference to item number \a i in this struct. If no such
    item exists, an empty QtSoapType is returned.

    The items are ordered in the sequence in which they were inserted,
    starting from 0.
*/
const QtSoapType &QtSoapStruct::operator [](int i) const
{
    static QtSoapType NIL;
    if (i < 0 || i >= dict.count())
        return NIL;

    return *dict[i].ptr();
}

/*!
    Returns a reference to the item in this struct whose QName
    (qualified name) is \a key. If no such item exists, an empty
    QtSoapType is returned.
*/
QtSoapType &QtSoapStruct::at(const QtSoapQName &key)
{
    static QtSoapType NIL;

    QListIterator<QtSmartPtr<QtSoapType> > it(dict);
    while (it.hasNext()) {
        QtSoapType *ret = it.next().ptr();
        if (ret->name() == key)
            return *ret;
    }

    return NIL;
}

/*!
    \overload

    Returns a reference to the item in this struct whose QName
    (qualified name) is \a key. If no such item exists, an empty
    QtSoapType is returned.
*/
const QtSoapType &QtSoapStruct::at(const QtSoapQName &key) const
{
    static QtSoapType NIL;

    for (QtSoapStructIterator i(*const_cast<QtSoapStruct *>(this)); i.current(); ++i)
	if (i.key() == key)
	    return *i.current();

    return NIL;
}

/*!
    Constructs a QtSoapStructIterator and initializes it to point to
    the first element in the struct \a s.
*/
QtSoapStructIterator::QtSoapStructIterator(QtSoapStruct &s) : it(s.dict.begin()), itEnd(s.dict.end())
{
}

/*!
    Destructs the QtSoapStructIterator.
*/
QtSoapStructIterator::~QtSoapStructIterator()
{
}


/*!
    Returns the QName (qualified name) of the current item.
*/
QtSoapQName QtSoapStructIterator::key() const
{
    if (it == itEnd)
        return QtSoapQName();
    return (*it)->name();
}

/*!
    Returns a pointer to the current item, or 0 if there is none.
*/
QtSoapType *QtSoapStructIterator::data()
{
    if (it == itEnd)
        return 0;
    return it->ptr();
}

/*!
    Returns a pointer to the current item, or 0 if there is none.
*/
const QtSoapType *QtSoapStructIterator::current() const
{
    if (it == itEnd)
        return 0;
    return it->ptr();
}

/*!
    Moves the iterator to the next item in the struct.
*/
void QtSoapStructIterator::operator ++()
{
    if (it == itEnd)
        return;
    ++it;
}

/*!
    Returns true if this iterator's position is not equal to that of
    \a j; otherwise returns false.
*/
bool QtSoapStructIterator::operator !=(const QtSoapStructIterator &j) const
{
    return it != j.it;
}

/*!
    Returns true if this iterator's position is equal to that of \a
    j; otherwise returns false.
*/
bool QtSoapStructIterator::operator ==(const QtSoapStructIterator &j) const
{
    return it == j.it;
}

/*!
    Constructs an empty QtSoapSimpleType.
*/
QtSoapSimpleType::QtSoapSimpleType()
{
}

/*!
    \overload

    Constructs an empty QtSoapSimpleType, and sets its QName
    (qualified name) to \a name.
*/
QtSoapSimpleType::QtSoapSimpleType(const QtSoapQName &name)
    : QtSoapType(name)
{
}

/*!
    \overload

    Constructs a QtSoapSimpleType of type Int. Sets its QName
    (qualified name) to \a name and its value to \a n.
*/
QtSoapSimpleType::QtSoapSimpleType(const QtSoapQName &name, int n)
    : QtSoapType(name, Int), v(QVariant(n))
{
}

/*!
    \overload

    Constructs a QtSoapSimpleType of type Boolean. Sets its QName
    (qualified name) to \a name and its value to \a n.

    \a dummy is an unused variable that should be set to 0; it is
    needed for older compilers that cannot distinguish between bool
    and int.
*/
QtSoapSimpleType::QtSoapSimpleType(const QtSoapQName &name, bool n, int)
    : QtSoapType(name, Boolean), v(QVariant(n))
{
}

/*!
    \overload

    Constructs a QtSoapSimpleType of type String. Sets its QName
    (qualified name) to \a name and its value to \a n.
*/
QtSoapSimpleType::QtSoapSimpleType(const QtSoapQName &name, const QString &n)
    : QtSoapType(name, String), v(QVariant(n))
{
}

/*!
    Constructs a QtSoapSimpleType that is a copy of \a copy.
*/
QtSoapSimpleType::QtSoapSimpleType(const QtSoapSimpleType &copy)
    : QtSoapType(copy), v(copy.v)
{
}

/*!
    Destructs the QtSoapSimpleType.
*/
QtSoapSimpleType::~QtSoapSimpleType()
{
}

/*!
    Erases the value of this QtSoapSimpleType.
*/
void QtSoapSimpleType::clear()
{
    v.clear();
}

/*!
    Returns the QDomElement representation of this QtSoapSimpleType.
    The returned QDomElement is created using \a doc.
*/
QDomElement QtSoapSimpleType::toDomElement(QDomDocument doc) const
{
    QString prefix = QtSoapNamespaces::instance().prefixFor(n.uri());
    QDomElement a = n.uri() == ""
		    ? doc.createElement(n.name())
		    : doc.createElementNS(n.uri(), prefix + ":" + n.name());

    QString schemaprefix = QtSoapNamespaces::instance().prefixFor(XML_SCHEMA_INSTANCE);
    a.setAttributeNS(XML_SCHEMA_INSTANCE, schemaprefix + ":type", "xsd:" + typeName());
    a.appendChild(doc.createTextNode(v.toString()));

    return a;
}

/*! \reimp
*/
bool QtSoapSimpleType::isValid() const
{
    return true;
}

/*!
    Makes this QtSoapSimpleType a copy of \a copy.
*/
QtSoapSimpleType &QtSoapSimpleType::operator =(const QtSoapSimpleType &copy)
{
    t = copy.t;
    errorStr = copy.errorStr;
    i = copy.i;
    n = copy.n;
    u = copy.u;
    h = copy.h;
    v = copy.v;

    return *this;
}

/*!
    Inspects \a node and constructs the QtSoapSimpleType content if \a
    node qualifies as a SOAP simple type. Returns true if it does;
    otherwise returns false.
*/
bool QtSoapSimpleType::parse(QDomNode node)
{
    if (node.isNull() || !node.isElement())
	return false;

    QDomElement e = node.toElement();

    QDomAttr typeattr = e.attributeNode("type");
    QString type = typeattr.isNull() ? QString("string") : localName(typeattr.value()).toLower();

    t = QtSoapType::nameToType(type);
    switch (t) {
    case Duration:
    case DateTime:
    case Time:
    case Date:
    case GYearMonth:
    case GYear:
    case GMonthDay:
    case GDay:
    case GMonth:
    case Base64Binary:
    case HexBinary:
    case AnyURI:
    case QName:
    case NOTATION:
    case String:
    case NormalizedString:
    case Token:
    case Language:
    case Name:
    case NMTOKEN:
    case NCName:
    case ID:
    case IDREF:
    case ENTITY:
	v = QVariant(e.text());
	break;
    case Float:
	v = QVariant(e.text().toFloat());
	break;
    case Double:
	v = QVariant(e.text().toDouble());
	break;
    case Decimal:
    case Integer:
    case NonPositiveInteger:
    case NegativeInteger:
    case Long:
    case Int:
    case Short:
    case Byte:
    case NonNegativeInteger:
    case UnsignedLong:
    case PositiveInteger:
    case UnsignedInt:
    case UnsignedShort:
    case UnsignedByte:
	if (e.text() == "" || (e.text() != "" && (e.text()[0].isNumber() || e.text()[0] == '-')))
	    v = QVariant(e.text().toInt());
	else {
	    errorStr = "Type error at element \"" + e.tagName() + "\"";
	    return false;
	}

	break;
    case Boolean: {
	QString val = e.text().trimmed().toLower();
	if (val == "false")
	    v = QVariant(false);
	else if (val == "true")
	    v = QVariant(true);
    }
	break;
    default:
	v = e.text();
	break;
    }

    setName(QtSoapQName(localName(e.tagName()), e.namespaceURI()));
    return true;
}

/*!
    Returns the value of the simple type as a QString.
*/
QString QtSoapSimpleType::toString() const
{
    return v.toString();
}

/*!
    Returns the value of the simple type as an int.
*/
int QtSoapSimpleType::toInt() const
{
    return v.toInt();
}

/*!
    Returns the value of the simple type as a bool.
*/
bool QtSoapSimpleType::toBool() const
{
    return v.toBool();
}


/*!
    Returns the QVariant value of this QtSoapSimpleType.
*/
QVariant QtSoapSimpleType::value() const
{
    return v;
}

/*! \class QtSoapMessage qtsoap.h
    \brief The QtSoapMessage class provides easy access to SOAP
    messages.

    With this class, you can create and inspect any SOAP message.
    There are convenience functions available for generating the most
    common types of SOAP messages, and any other messages can be
    constructed manually using addBodyItem().

    Use setMethod() and addMethodArgument() to construct a method
    request. The return value of a method response is available
    from returnValue().

    Use setFaultCode(), setFaultString() and addFaultDetail() to
    construct a Fault message. To inspect a Fault message, use
    faultCode(), faultString() and faultDetail().

    To add items to the body part of the SOAP message, use
    addBodyItem(). To add items to the header, use addHeaderItem().

    toXmlString() returns a QString XML representation of the SOAP
    message. clear() resets all content in the message, creating an
    empty SOAP message.

    \code
    QtSoapMessage message;

    message.setMethod("getTemperature", "http://weather.example.com/temperature");
    message.addMethodArgument("city", "Oslo");

    // Get the SOAP message as an XML string.
    QString xml = message.toXmlString();
    \endcode

    QtSoap provides a partial implementation of version 1.1 of the
    SOAP protocol as defined in \l http://www.w3.org/TR/SOAP/.

    \list
    \i Server side SOAP is not supported.
    \i References to values (id and href attributes) are not supported.
    \i Arrays support a maximum of five dimensions.
    \i Namespaces for types are not checked. Only the type names are used.
    \i The encodingStyle attribute is ignored. The serialization and
       encoding rules from section 5 in the SOAP v1.1 specification
       are assumed regardless of the value of the encodingStyle
       attribute.
    \i QtSoapType does not have accessors for attributes, which means
       for example that actor, mustUnderstand and so on are not
       accessible in headers.
    \i The SOAP root attribute is not supported.
    \endlist

    \sa QtSoapType, QtSoapQName, QtSoapHttpTransport

*/

/*! \enum QtSoapMessage::FaultCode

    This enum describes all the supported SOAP Fault codes:

    \value VersionMismatch
    The namespace for the Envelope element was unrecognized by the
    remote SOAP server. This usually means that the remote server does
    not support version 1.1 of the SOAP protocol.

    \value MustUnderstand
    One of the header items in the SOAP message with a
    "MustUnderstand" attribute was not recognized by the remote
    server.

    \value Client
    An error in the SOAP message or transport prevents further
    processing by the remote SOAP server.

    \value Server
    An error in the remote SOAP server prevents it from processing the
    SOAP message.

    \omitvalue Other
*/

/*! \enum QtSoapMessage::MessageType

    \value Fault
    \value MethodRequest
    \value MethodResponse
    \value OtherType

*/

/*!
    Constructs an empty QtSoapMessage. The message only contains the
    Envelope element, with no header and no body.
*/
QtSoapMessage::QtSoapMessage()
    : type(OtherType), envelope(QtSoapQName("Envelope", SOAPv11_ENVELOPE))
{
    init();
}

/*!
    Constructs a copy of \a copy.
*/
QtSoapMessage::QtSoapMessage(const QtSoapMessage &copy)
    : type(copy.type), envelope(copy.envelope), m(copy.m), margs(copy.margs),
      errorStr(copy.errorStr)
{
    init();
}

/*!
    Destructs a QtSoapMessage.
*/
QtSoapMessage::~QtSoapMessage()
{
}

/*! \internal

    Registers the standard SOAP namespaces with prefixes.
*/
void QtSoapMessage::init()
{
    QtSoapNamespaces::instance().registerNamespace("SOAP-ENV", SOAPv11_ENVELOPE);
    QtSoapNamespaces::instance().registerNamespace("SOAP-ENC", SOAPv11_ENCODING);
    QtSoapNamespaces::instance().registerNamespace("xsi", XML_SCHEMA_INSTANCE);
    QtSoapNamespaces::instance().registerNamespace("xsd", XML_SCHEMA);
}

/*!
    Clears the content of the SOAP message.
*/
void QtSoapMessage::clear()
{
    type = OtherType;
    envelope.clear();
    m = QtSoapQName();
    margs.clear();
    errorStr = "Unknown error";
}

/*!
    Makes this message a copy of \a copy.
*/
QtSoapMessage &QtSoapMessage::operator =(const QtSoapMessage &copy)
{
    envelope = copy.envelope;
    m = copy.m;
    margs = copy.margs;
    errorStr = copy.errorStr;
    return *this;
}

/*!
    Imports the QDomDocument \a d if it validates as a SOAP
    message. Any existing message content is replaced.

    If the import fails, this message becomes a Fault message.

    Returns true if the import succeeds, otherwise false.
*/
bool QtSoapMessage::setContent(QDomDocument &d)
{
    if (isValidSoapMessage(d)) {
	clear();
        QDomNode node = d.firstChild();
        if (!node.isElement())
            node = node.nextSibling();

	if (envelope.parse(node))
	    return true;
    }

    return false;
}

/*!
    \overload

    Parses the XML document in \a buffer. Imports the document if it
    validates as a SOAP message. Any existing message content is
    replaced.

    If the import fails, this message becomes a Fault message.

    Returns true if the import succeeds, otherwise false.
*/
bool QtSoapMessage::setContent(const QByteArray &buffer)
{
    int errorLine, errorColumn;
    QString errorMsg;

    QDomDocument doc;
    if (!doc.setContent(buffer, true, &errorMsg,
			&errorLine, &errorColumn)) {
	QString s;
	s.sprintf("%s at line %i, column %i", errorMsg.toLatin1().constData(),
		  errorLine, errorColumn);
	setFaultCode(VersionMismatch);
	setFaultString("XML parse error");
	addFaultDetail(new QtSoapSimpleType(QtSoapQName("ParseError"), s));
	return false;
    }

    if (!isValidSoapMessage(doc))
	return false;

    QDomNode node = doc.firstChild();
    if (!node.isElement())
	node = node.nextSibling();
    bool res = envelope.parse(node);
    if (!res)
	qDebug("QtSoapMessage::setContent(), parsing failed: %s", envelope.errorString().toLatin1().constData());
    return res;
}

/*!
    Validates the QDomDocument \a candidate using some simple
    heuristics. Returns true if the document is a valid SOAP message;
    otherwise returns false.
*/
bool QtSoapMessage::isValidSoapMessage(const QDomDocument &candidate)
{
    QDomNode tmp = candidate.firstChild();
    if (tmp.isNull())
	return false;

    // Skip the initial processing instruction if there is one. Most
    // likely this isn't actually a processing instruction, but rather
    // the initial xml declaration <?xml...
    if (tmp.isProcessingInstruction()) {
	tmp = tmp.nextSibling();

	if (tmp.isNull() || !tmp.isElement())
	    return false;
    }

    QDomElement tmpe = tmp.toElement();

    if (localName(tmpe.tagName()).toUpper() != "ENVELOPE") {
	setFaultCode(VersionMismatch);
	setFaultString("SOAP structure invalid");
	addFaultDetail(new QtSoapSimpleType(QtSoapQName("extra"), "root element \"" + tmpe.localName()
					+ "\"/\"" + tmpe.tagName() + "\" is not envelope"));
	return false;
    }

    tmp = tmp.firstChild();
    if (tmp.isNull() || !tmp.isElement()) {
	setFaultCode(VersionMismatch);
	setFaultString("SOAP structure invalid");
	addFaultDetail(new QtSoapSimpleType(QtSoapQName("extra"), "mandatory body element missing"));
	return false;
    }

    QDomElement tmpe2 = tmp.toElement();

    bool foundHeader = false;
    if (localName(tmpe2.tagName()).toUpper() == "HEADER") {
	foundHeader = true;
	tmp = tmp.nextSibling();
    }

    if (!foundHeader && (tmp.isNull() || !tmp.isElement())) {
	setFaultCode(VersionMismatch);
	setFaultString("SOAP structure invalid");
	addFaultDetail(new QtSoapSimpleType(QtSoapQName("extra"), "mandatory body element missing"));
	return false;
    }

    QDomElement tmpe3 = tmp.toElement();

    if (localName(tmpe3.tagName()).toUpper() != "BODY") {
	setFaultCode(VersionMismatch);
	setFaultString("SOAP structure invalid");
	addFaultDetail(new QtSoapSimpleType(QtSoapQName("extra"), "mandatory body element missing"));
	return false;
    }

    // At this point, check that the version of the envelope is
    // correct.
    if (tmpe.namespaceURI() != SOAPv11_ENVELOPE) {
	setFaultCode(VersionMismatch);
	setFaultString("SOAP structure invalid");
	addFaultDetail(new QtSoapSimpleType(QtSoapQName("extra"), "Unsupported namespace for envelope element"));
	return false;
    }

    return true;
}

/*!
    Returns the XML representation of the SOAP message as a QString,
    optionally indenting using \a indent spaces.
*/
QString QtSoapMessage::toXmlString(int indent) const
{
    QDomImplementation impl;
    QDomDocument doc = impl.createDocument(QString(), QString("placeholder"),
                                           QDomDocumentType());
    doc.removeChild(doc.firstChild());
    doc.appendChild(envelope.toDomElement(doc));

    QDomElement env = doc.firstChild().toElement();

    env.setAttribute(QtSoapNamespaces::instance().prefixFor(SOAPv11_ENVELOPE)
		     + ":" + "encodingStyle",
		     SOAPv11_ENCODING);

    env.setAttribute("xmlns:" + QtSoapNamespaces::instance().prefixFor(XML_SCHEMA),
		     XML_SCHEMA);

    return doc.toString(indent);
}

/*!
    Returns a human readable explanation of the most recent error that
    occurred in the QtSoapMessage.
*/
QString QtSoapMessage::errorString() const
{
    return errorStr;
}

/*!
    Adds \a item to the body in the SOAP message. The item is added
    after the last existing item in the body.
*/
void QtSoapMessage::addBodyItem(QtSoapType *item)
{
    body().insert(item);
}

/*!
    Adds \a item to the header in the SOAP message. The item is added
    after the last existing item in the header.
*/
void QtSoapMessage::addHeaderItem(QtSoapType *item)
{
    QtSoapType &headerTmp = envelope[QtSoapQName("Header", SOAPv11_ENVELOPE)];
    if (!headerTmp.isValid())
	envelope.insert(new QtSoapStruct(QtSoapQName("Header", SOAPv11_ENVELOPE)));

    QtSoapStruct &header = (QtSoapStruct &)envelope[QtSoapQName("Header", SOAPv11_ENVELOPE)];
    header.insert(item);
}
/*!
    Returns the return value of a SOAP method response as a
    QtSoapType.
*/
const QtSoapType &QtSoapMessage::returnValue() const
{
    static QtSoapType NIL;

    const QtSoapType &meth = method();

    if (!meth.isValid() || meth.type() != QtSoapType::Struct)
	return NIL;

    QtSoapStruct &m = (QtSoapStruct &) meth;
    if (m.count() == 0)
	return NIL;

    QtSoapStructIterator mi(m);
    return *mi.data();
}

/*!
    Returns the Fault detail element of a SOAP Fault message.
*/
const QtSoapType &QtSoapMessage::faultDetail() const
{
    return body()[QtSoapQName("Fault", SOAPv11_ENVELOPE)][QtSoapQName("Detail")];
}

/*!
    Returns the Fault faultstring element of a SOAP Fault message.
*/
const QtSoapType &QtSoapMessage::faultString() const
{
    return body()[QtSoapQName("Fault", SOAPv11_ENVELOPE)][QtSoapQName("Faultstring")];
}

/*!
    Returns true if the message is a SOAP Fault message; otherwise
    returns false.
*/
bool QtSoapMessage::isFault() const
{
    return faultCode() != Other;
}

/*!
    Returns the Fault faultcode element of a SOAP Fault message.
*/
QtSoapMessage::FaultCode QtSoapMessage::faultCode() const
{
    QtSoapType &code = body()[QtSoapQName("Fault")][QtSoapQName("Faultcode")];
    if (!code.isValid() || (code.type() != QtSoapType::String
                            && code.type() != QtSoapType::QName))
	return Other;

    QtSoapSimpleType &fcode = (QtSoapSimpleType &)code;
    QString fcodestr = fcode.value().toString();

    // Only test string before first .
    int pos;
    if ((pos = fcodestr.indexOf('.')) != -1)
        fcodestr.truncate(pos);

    if (localName(fcodestr.toLower()) == "versionmismatch")
	return VersionMismatch;

    if (localName(fcodestr.toLower()) == "mustunderstand")
	return MustUnderstand;

    if (localName(fcodestr.toLower()) == "client")
	return Client;

    if (localName(fcodestr.toLower()) == "server")
	return Server;

    return Other;
}

/*!
    Returns a reference to the body of the SOAP message.
*/
QtSoapStruct &QtSoapMessage::body() const
{
    const QtSoapQName bodyName("Body", SOAPv11_ENVELOPE);

    QtSoapType &bodyTmp = envelope[bodyName];
    if (!bodyTmp.isValid())
	envelope.insert(new QtSoapStruct(bodyName));

    return (QtSoapStruct &)envelope[bodyName];
}

/*!
    Returns a reference to the header of the SOAP message.
*/
QtSoapStruct &QtSoapMessage::header() const
{
    const QtSoapQName headerName("Header", SOAPv11_ENVELOPE);

    QtSoapType &headerTmp = envelope[headerName];
    if (!headerTmp.isValid())
	envelope.insert(new QtSoapStruct(headerName));

    return (QtSoapStruct &)envelope[headerName];
}

/*!
    Sets the fault code of the SOAP Fault message to \a code.
*/
void QtSoapMessage::setFaultCode(FaultCode code)
{
    if (type != Fault && type != OtherType) {
	clear();
	type = Fault;
    }

    if (!body()[QtSoapQName("Fault", SOAPv11_ENVELOPE)].isValid())
	addBodyItem(new QtSoapStruct(QtSoapQName("Fault", SOAPv11_ENVELOPE)));

    QString codeStr;
    switch (code) {
    case VersionMismatch:
	codeStr = "SOAP-ENV:VersionMismatch";
	break;
    case MustUnderstand:
	codeStr = "SOAP-ENV:MustUnderstand";
	break;
    case Client:
	codeStr = "SOAP-ENV:Client";
	break;
    case Server:
	codeStr = "SOAP-ENV:Server";
	break;
    case Other:
	codeStr = "Other";
	break;
    }

    QtSoapType &node = body()[QtSoapQName("Fault", SOAPv11_ENVELOPE)];
    QtSoapStruct &fault = reinterpret_cast<QtSoapStruct &>(node);
    fault.insert(new QtSoapSimpleType(QtSoapQName("Faultcode"), codeStr));
}

/*!
    Sets the Fault faultstring of the SOAP Fault message to \a s.
*/
void QtSoapMessage::setFaultString(const QString &s)
{
    if (type != Fault && type != OtherType) {
	clear();
	type = Fault;
    }

    if (!body()[QtSoapQName("Fault", SOAPv11_ENVELOPE)].isValid())
	addBodyItem(new QtSoapStruct(QtSoapQName("Fault", SOAPv11_ENVELOPE)));

    QtSoapType &node = body()[QtSoapQName("Fault", SOAPv11_ENVELOPE)];
    QtSoapStruct &fault = reinterpret_cast<QtSoapStruct &>(node);
    fault.insert(new QtSoapSimpleType(QtSoapQName("Faultstring"), s));
}

/*!
   Adds the QtSoapType \a detail to the end of the list of faultdetail
   items in a SOAP Fault message.
*/
void QtSoapMessage::addFaultDetail(QtSoapType *detail)
{
    if (type != Fault && type != OtherType) {
	clear();
	type = Fault;
    }

    if (!body()[QtSoapQName("Fault", SOAPv11_ENVELOPE)].isValid())
	addBodyItem(new QtSoapStruct(QtSoapQName("Fault", SOAPv11_ENVELOPE)));

    QtSoapType &node = body()[QtSoapQName("Fault", SOAPv11_ENVELOPE)];
    QtSoapStruct &fault = reinterpret_cast<QtSoapStruct &>(node);
    if (!fault[QtSoapQName("Faultdetail", SOAPv11_ENVELOPE)].isValid())
	fault.insert(new QtSoapStruct(QtSoapQName("Faultdetail", SOAPv11_ENVELOPE)));

    QtSoapType &node2 = fault[QtSoapQName("Faultdetail", SOAPv11_ENVELOPE)];
    QtSoapStruct &fdetail = reinterpret_cast<QtSoapStruct &>(node2);

    fdetail.insert(detail);
}

/*!
    Returns the method of a SOAP method request or response
    as a QtSoapType.
*/
const QtSoapType &QtSoapMessage::method() const
{
    static QtSoapType NIL;

    if (body().count() == 0)
	return NIL;

    QtSoapStructIterator it(body());

    return *it.data();
}

/*!
    Sets the QName (qualified name) of the method to call in a SOAP
    method request to \a meth.

    This function \e must be called before calling
    addMethodArgument().
*/
void QtSoapMessage::setMethod(const QtSoapQName &meth)
{
    if (type != MethodRequest && type != OtherType) {
	clear();
	type = MethodRequest;
    }

    addBodyItem(new QtSoapStruct(meth));
}

/*! \overload

    Sets the method name to \a name and uri to \a uri.
*/
void QtSoapMessage::setMethod(const QString &name, const QString &uri)
{
    setMethod(QtSoapQName(name, uri));
}

/*!
   Adds argument \a arg to the list of arguments that are passed in a
   SOAP method request.

   \warning setMethod() must be called before calling this function.
*/
void QtSoapMessage::addMethodArgument(QtSoapType *arg)
{
    if (body().count() == 0) {
	qWarning("Attempted to add argument (%s:%s) without first setting method",
		 arg->name().uri().toLatin1().constData(), arg->name().name().toLatin1().constData());
	return;
    }

    QtSoapStructIterator it(body());
    QtSoapType &node = *it.data();
    QtSoapStruct &meth = static_cast<QtSoapStruct &>(node);
    meth.insert(arg);
}

/*! \overload

    Adds an argument called \a name with a uri of \a uri. The type
    of the argument is QtSoapType::String and its value is \a value.
*/
void QtSoapMessage::addMethodArgument(const QString &name, const QString &uri, const QString &value)
{
    addMethodArgument(new QtSoapSimpleType(QtSoapQName(name, uri), value));
}

/*! \overload

    Adds an argument called \a name with a uri of \a uri. The type
    of the argument is QtSoapType::Boolean and its value is \a value.

    The \a dummy argument is used to distinguish this function from
    the overload which takes an int.
*/
void QtSoapMessage::addMethodArgument(const QString &name, const QString &uri, bool value, int dummy)
{
    addMethodArgument(new QtSoapSimpleType(QtSoapQName(name, uri), value, dummy));
}

/*! \overload

    Adds an argument called \a name with a uri of \a uri. The type
    of the argument is QtSoapType::Integer and its value is \a value.
*/
void QtSoapMessage::addMethodArgument(const QString &name, const QString &uri, int value)
{
    addMethodArgument(new QtSoapSimpleType(QtSoapQName(name, uri), value));
}

/*!
    Constructs a QtSoapTypeFactory and initializes it with all the
    known SOAP types.
*/
QtSoapTypeFactory::QtSoapTypeFactory()
{
    QtSoapTypeConstructor<QtSoapStruct> *structConstructor = new QtSoapTypeConstructor<QtSoapStruct>();
    deleteList.append(structConstructor);
    QtSoapTypeConstructor<QtSoapArray> *arrayConstructor = new QtSoapTypeConstructor<QtSoapArray>();
    deleteList.append(arrayConstructor);
    QtSoapTypeConstructor<QtSoapSimpleType> *basicTypeConstructor = new QtSoapTypeConstructor<QtSoapSimpleType>();
    deleteList.append(basicTypeConstructor);

    registerHandler("struct", structConstructor);
    registerHandler("array", arrayConstructor);
    registerHandler("string", basicTypeConstructor);
    registerHandler("normalizedstring", basicTypeConstructor);
    registerHandler("token", basicTypeConstructor);
    registerHandler("language", basicTypeConstructor);
    registerHandler("name", basicTypeConstructor);
    registerHandler("ncname", basicTypeConstructor);
    registerHandler("id", basicTypeConstructor);
    registerHandler("idref", basicTypeConstructor);
    registerHandler("entity", basicTypeConstructor);
    registerHandler("nmtoken", basicTypeConstructor);
    registerHandler("nmtokens", basicTypeConstructor);
    registerHandler("boolean", basicTypeConstructor);
    registerHandler("decimal", basicTypeConstructor);
    registerHandler("integer", basicTypeConstructor);
    registerHandler("nonpositiveinteger", basicTypeConstructor);
    registerHandler("negativeinteger", basicTypeConstructor);
    registerHandler("int", basicTypeConstructor);
    registerHandler("long", basicTypeConstructor);
    registerHandler("short", basicTypeConstructor);
    registerHandler("byte", basicTypeConstructor);
    registerHandler("nonnegativeinteger", basicTypeConstructor);
    registerHandler("unsignedlong", basicTypeConstructor);
    registerHandler("unsignedint", basicTypeConstructor);
    registerHandler("unsignedshort", basicTypeConstructor);
    registerHandler("unsignedbyte", basicTypeConstructor);
    registerHandler("positiveinteger", basicTypeConstructor);
    registerHandler("float", basicTypeConstructor);
    registerHandler("double", basicTypeConstructor);
    registerHandler("other", structConstructor);
}

/*!
    Destructs the QtSoapTypeFactory. This destructor is called when
    the application exits.
*/
QtSoapTypeFactory::~QtSoapTypeFactory()
{
    QLinkedList<QtSoapTypeConstructorBase*>::ConstIterator it = deleteList.begin();
    while (it != deleteList.end()) {
        delete *it;
        ++it;
    }
}

/*!
    Returns a reference to the QtSoapTypeFactory singleton.
*/
QtSoapTypeFactory &QtSoapTypeFactory::instance()
{
    static QtSoapTypeFactory factory;
    return factory;
}

/*!
    Registers a handler \a handler for a QtSoapType called \a name.
*/
bool QtSoapTypeFactory::registerHandler(const QString &name, QtSoapTypeConstructorBase *handler)
{
    if (typeHandlers.find(name) != typeHandlers.end()) {
	errorStr = "A handler for " + name + " is already registered.";
	return false;
    }

    typeHandlers.insert(name, handler);
    return true;
}

/*! \internal
*/
QtSmartPtr<QtSoapType> QtSoapTypeFactory::soapType(QDomNode node) const
{
    if (node.isNull() || !node.isElement())
	return QtSmartPtr<QtSoapType>();

    QDomElement elem = node.toElement();

    QDomAttr attr = elem.attributeNode("type");
    QtSoapTypeConstructorBase *constructor = 0;
    if (!attr.isNull()) {
        QHash<QString, QtSoapTypeConstructorBase *>::ConstIterator it;
	it = typeHandlers.find(localName(attr.value().toLower()));
        if (it != typeHandlers.end())
            constructor = *it;
    }

    if (attr.isNull() || !constructor) {
        QHash<QString, QtSoapTypeConstructorBase *>::ConstIterator it;
	if (node.firstChild().isElement()) {
            if (localName(node.nodeName().toLower()) == "array") {
                it = typeHandlers.find("array");
            } else
                it = typeHandlers.find("struct");
        } else
	    it = typeHandlers.find("string");
        if (it != typeHandlers.end())
            constructor = *it;
    }

    if (!constructor) {
	return QtSmartPtr<QtSoapType>();
    }

    QtSoapType *type = constructor->createObject(node);

    if (!type)
	errorStr = constructor->errorString();

    return QtSmartPtr<QtSoapType>(type);
}

/*!
    Returns a human readable interpretation of the last error
    that occurred.
*/
QString QtSoapTypeFactory::errorString() const
{
    return errorStr;
}

/*! \class QtSoapHttpTransport

    \brief The QtSoapHttpTransport class provides a mechanism for
    transporting SOAP messages to and from other hosts using the
    HTTP protocol.

    Use this class to submit SOAP messages to a web service.
    Set the hostname of the SOAP server with setHost(). Some servers
    also require the SOAPAction header to be set, and you can do this
    with setAction(). Next, submit the request with submitRequest(),
    passing the message to submit together with the path that you want
    to submit the message to. The responseReady() signal is emitted
    when a response has been received. Call getResponse() to get the
    reponse from the service.

    QtSoapHttpTransport usage example: If a SOAP weather service was
    running on the host weather.example.com, the following code might
    be used to find the temperature in any given city:

    \code
    void WeatherFetcher::findTemperature(const QString &city)
    {
        QtSoapMessage message;
        message.setMethod("getTemperature", "http://weather.example.com/temperature");
        message.setMethodArgument("city", "", city);

        // transport is a private member of WeatherFetcher, of type QtSoapHttpTransport
        transport.setHost("www.example.com");
        connect(&transport, SIGNAL(responseReady()), SLOT(readResponse()));

        transport.submitRequest(message, "/weatherfetcher/fetch.asp");
    }
    \endcode

    This is an example implementation of the readResponse() slot in
    the WeatherFetcher class:

    \code
    void WeatherFetcher::readResponse()
    {
        const QtSoapMessage &response = transport.getResponse();
        if (response.isFault()) {
            cout << response.faultString().toString().toLatin1().constData() << endl;
            return;
        }

        const QtSoapType &returnValue = response.returnValue();
        if (returnValue["temperature"].isValid()) {
        cout << "The current temperature is "
             << returnValue["temperature"].toString().toLatin1().constData()
             << " degrees Celcius." << endl;
    }
    \endcode

    \sa QtSoapMessage, QtSoapType
*/

/*! \fn void QtSoapHttpTransport::responseReady()

    This signal is emitted when a SOAP response is received from a
    remote peer.

    \sa getResponse()
*/

/*! \fn void QtSoapHttpTransport::responseReady(const QtSoapMessage &response)

    This signal is emitted when a SOAP response is received from a
    remote peer. The received response is available in \a
    response. This signal is emitted in tandem with the argument-less
    responseReady() signal.

    \sa responseReady()
*/

/*!
    Constructs a QtSoapHttpTransport object. Passes \a parent to
    QObject's constructor.
*/

QtSoapHttpTransport::QtSoapHttpTransport(QObject *parent)
    : QObject(parent), networkMgr(this)
{
    connect(&networkMgr, SIGNAL(finished(QNetworkReply *)),
            SLOT(readResponse(QNetworkReply *)));
}

/*!
    Destructs a QtSoapHttpTransport.
*/
QtSoapHttpTransport::~QtSoapHttpTransport()
{
}

/*!
  \obsolete
*/

void QtSoapHttpTransport::setHost(const QString &host, int port)
{
    setHost(host, false, port);
}

/*!
  Sets the \a host this transport should connect to. The transport
  mode will be HTTP, unless \a useSecureHTTP is set, in which case it
  will be HTTPS. This transport will connect to the well-known ports
  by default (80 for HTTP, 443 for HTTPS), unless a different,
  non-zero port is specified in \a port.
*/
void QtSoapHttpTransport::setHost(const QString &host, bool useSecureHTTP, int port)
{
    url.setHost(host);
    url.setScheme(useSecureHTTP ? QLatin1String("https") : QLatin1String("http"));
    if (port)
        url.setPort(port);
    else
        url.setPort(useSecureHTTP ? 443 : 80);
}

/*!
    Sets the HTTP header SOAPAction to \a action.
*/
void QtSoapHttpTransport::setAction(const QString &action)
{
    soapAction = action;
}

/*!
    Submits the SOAP message \a request to the path \a path on the
    HTTP server set using setHost().
*/
void QtSoapHttpTransport::submitRequest(QtSoapMessage &request, const QString &path)
{
    QNetworkRequest networkReq;
    networkReq.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("text/xml;charset=utf-8"));
    networkReq.setRawHeader("SOAPAction", soapAction.toAscii());
    url.setPath(path);
    networkReq.setUrl(url);

    soapResponse.clear();
    networkRep = networkMgr.post(networkReq, request.toXmlString().toUtf8().constData());
}


/*!
    Returns the most recently received response SOAP message. This
    message could be a Fault message, so it is wise to check using
    QtSoapMessage::isFault() before processing the response.
*/
const QtSoapMessage &QtSoapHttpTransport::getResponse() const
{
    return soapResponse;
}


/*!
    Returns a pointer to the QNetworkAccessManager object used by this
    transport. This is useful if the application needs to connect to its
    signals, or set or read its cookie jar, etc.
*/

QNetworkAccessManager *QtSoapHttpTransport::networkAccessManager()
{
    return &networkMgr;
}


/*!
    Returns a pointer to the QNetworkReply object of the current (or last)
    request, or 0 if no such object is currently available.

    This is useful if the application needs to access the raw header
    data etc.
*/

QNetworkReply *QtSoapHttpTransport::networkReply()
{
    return networkRep;
}

/*!

*/

void QtSoapHttpTransport::readResponse(QNetworkReply *reply)
{
    networkRep = reply;
    switch (reply->error()) {
    case QNetworkReply::NoError:
    case QNetworkReply::ContentAccessDenied:
    case QNetworkReply::ContentOperationNotPermittedError:
    case QNetworkReply::ContentNotFoundError:
    case QNetworkReply::UnknownContentError:
        {
            soapResponse.setContent(reply->readAll());

            int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
            if (httpStatus != 200 && httpStatus != 100) {
                if (soapResponse.faultCode() == QtSoapMessage::Other)
                    soapResponse.setFaultCode(QtSoapMessage::Client);
                /*
                QString httpReason = reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
                soapResponse.setFaultString(QString("HTTP status %2 (%3).\n%1").arg(soapResponse.faultString().toString()).arg(httpStatus).arg(httpReason));
                */
            }
        }
        break;
    default:
        {
            soapResponse.setFaultCode(QtSoapMessage::Client);
            soapResponse.setFaultString(QString("Network transport error (%1): %2").arg(reply->error()).arg(reply->errorString()));
        }
        break;
    }

    emit responseReady();
    emit responseReady(soapResponse);

    reply->deleteLater();
}

/*! \class QtSoapNamespaces qtsoap.h

    \brief The QtSoapNamespaces class provides a registry for XML
    namespaces and prefixes for use in QtSoap.

    When a QtSoapMessage is converted to XML via
    QtSoapMessage::toXmlString(), this class is used to find
    appropriate XML namespace prefixes for the QNames (qualified
    names) in the message.

    To register a namespace with a prefix, call register().
    prefixFor() will then return the prefix that is registered for the
    given namespace, if any.

    To access the QtSoapNamespaces registry, call
    QtSoapNamespaces::instance().

    \code
    QtSoapNamespaces &registry = QtSoapNamespaces::instance();

    registry.register("pre", "http://www.example.com/");
    QString prefix = registry.prefixFor("http://www.example.com/"); // returns "pre"
    \endcode

    \sa QtSoapMessage
*/

/*!
    Returns a reference to the QtSoapNamespaces singleton.
*/
QtSoapNamespaces &QtSoapNamespaces::instance()
{
    static QtSoapNamespaces ns;
    return ns;
}

/*! \internal

    Constructs a QtSoapNamespaces object.
*/
QtSoapNamespaces::QtSoapNamespaces()
{
}

/*!
    Registers the namespace \a uri with the prefix \a prefix.
*/
void QtSoapNamespaces::registerNamespace(const QString &prefix, const QString &uri)
{
    namespaces.insert(uri, prefix);
}

/*!
    Returns the prefix for the namespace \a uri, or an empty string if
    no prefix has been registered for \a uri.
*/
QString QtSoapNamespaces::prefixFor(const QString &uri)
{
    return namespaces.value(uri);
}