Files
@ f43d1a4680a9
Branch filter:
Location: hot67beta/libraries/domit/xml_domit_parser.php
f43d1a4680a9
106.9 KiB
text/x-php
menubar 0 to 10
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 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 | <?php
/**
* DOMIT! is a non-validating, but lightweight and fast DOM parser for PHP
* @package domit-xmlparser
* @subpackage domit-xmlparser-main
* @version 1.01
* @copyright (C) 2004 John Heinstein. All rights reserved
* @license http://www.gnu.org/copyleft/lesser.html LGPL License
* @author John Heinstein <johnkarl@nbnet.nb.ca>
* @link http://www.engageinteractive.com/domit/ DOMIT! Home Page
* DOMIT! is Free Software
**/
if (!defined('DOMIT_INCLUDE_PATH')) {
define('DOMIT_INCLUDE_PATH', (dirname(__FILE__) . "/"));
}
/** current version of DOMIT! */
define ('DOMIT_VERSION', '1.01');
/** XML namespace URI */
define ('DOMIT_XML_NAMESPACE', 'http://www.w3.org/xml/1998/namespace');
/** XMLNS namespace URI */
define ('DOMIT_XMLNS_NAMESPACE', 'http://www.w3.org/2000/xmlns/');
/**
* @global array Flipped version of $definedEntities array, to allow two-way conversion of entities
*
* Made global so that Attr nodes, which have no ownerDocument property, can access the array
*/
$GLOBALS['DOMIT_defined_entities_flip'] = array();
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_shared.php');
/**
* The base class of all DOMIT node types
*
* @package domit-xmlparser
* @subpackage domit-xmlparser-main
* @author John Heinstein <johnkarl@nbnet.nb.ca>
*/
class DOMIT_Node {
/** @var string The name of the node, varies according to node type */
var $nodeName = null;
/** @var string The value of the node, varies according to node type */
var $nodeValue = null;
/** @var int The type of node, e.g. CDataSection */
var $nodeType = null;
/** @var Object A reference to the parent of the current node */
var $parentNode = null;
/** @var Array An array of child node references */
var $childNodes = null;
/** @var Object A reference to the first node in the childNodes list */
var $firstChild = null;
/** @var Object A reference to the last node in the childNodes list */
var $lastChild = null;
/** @var Object A reference to the node prior to the current node in its parents childNodes list */
var $previousSibling = null;
/** @var Object A reference to the node after the current node in its parents childNodes list */
var $nextSibling = null;
/** @var Object A NodeList of attribute nodes */
var $attributes = null;
/** @var Object A reference to the Document node */
var $ownerDocument = null;
/** @var String A URI that identifies the XML namespace to which the node belongs */
var $namespaceURI = null;
/** @var String The namespace prefix for the node */
var $prefix = null;
/** @var String The local name of the node */
var $localName = null;
/** @var string The unique node id */
var $uid;
/** @var int The number of children of the current node */
var $childCount = 0;
/**
* Raises error if abstract class is directly instantiated
*/
function DOMIT_Node() {
DOMIT_DOMException::raiseException(DOMIT_ABSTRACT_CLASS_INSTANTIATION_ERR,
'Cannot instantiate abstract class DOMIT_Node');
} //DOMIT_Node
/**
* DOMIT_Node constructor, assigns a uid
*/
function _constructor() {
global $uidFactory;
$this->uid = $uidFactory->generateUID();
} //_constructor
/**
* Appends a node to the childNodes list of the current node
* @abstract
* @param Object The node to be appended
* @return Object The appended node
*/
function &appendChild(&$child) {
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Method appendChild cannot be called by class ' . get_class($this)));
} //appendChild
/**
* Inserts a node to the childNodes list of the current node
* @abstract
* @param Object The node to be inserted
* @param Object The node before which the insertion is to occur
* @return Object The inserted node
*/
function &insertBefore(&$newChild, &$refChild) {
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Method insertBefore cannot be called by class ' . get_class($this)));
} //insertBefore
/**
* Replaces a node with another
* @abstract
* @param Object The new node
* @param Object The old node
* @return Object The new node
*/
function &replaceChild(&$newChild, &$oldChild) {
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Method replaceChild cannot be called by class ' . get_class($this)));
} //replaceChild
/**
* Removes a node from the childNodes list of the current node
* @abstract
* @param Object The node to be removed
* @return Object The removed node
*/
function &removeChild(&$oldChild) {
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Method removeChild cannot be called by class ' . get_class($this)));
} //removeChild
/**
* Returns the index of the specified node in a childNodes list
* @param Array The childNodes array to be searched
* @param Object The node targeted by the search
* @return int The index of the target node, or -1 if not found
*/
function getChildNodeIndex(&$arr, &$child) {
$index = -1;
$total = count($arr);
for ($i = 0; $i < $total; $i++) {
if ($child->uid == $arr[$i]->uid) {
$index = $i;
break;
}
}
return $index;
} //getChildNodeIndex
/**
* Determines whether a node has any children
* @return boolean True if any child nodes are present
*/
function hasChildNodes() {
return ($this->childCount > 0);
} //hasChildNodes
/**
* Determines whether a node has any attributes
* @return boolean True if the node has attributes
*/
function hasAttributes() {
//overridden in DOMIT_Element
return false;
} //hasChildNodes
/**
* Collapses adjacent text nodes in entire node subtree
*/
function normalize() {
if (($this->nodeType == DOMIT_DOCUMENT_NODE) && ($this->documentElement != null)) {
$this->documentElement->normalize();
}
} //normalize
/**
* Copies a node and/or its children
* @abstract
* @param boolean True if all child nodes are also to be cloned
* @return Object A copy of the node and/or its children
*/
function &cloneNode($deep = false) {
DOMIT_DOMException::raiseException(DOMIT_ABSTRACT_METHOD_INVOCATION_ERR,
'Cannot invoke abstract method DOMIT_Node->cloneNode($deep). Must provide an overridden method in your subclass.');
} //cloneNode
/**
* Adds elements with the specified tag name to a NodeList collection
* @param Object The NodeList collection
* @param string The tag name of matching elements
*/
function getNamedElements(&$nodeList, $tagName) {
//Implemented in DOMIT_Element.
//Needs to be here though! This is called against all nodes in the document.
} //getNamedElements
/**
* Sets the ownerDocument property of a node to the containing DOMIT_Document
* @param Object A reference to the document element of the DOMIT_Document
*/
function setOwnerDocument(&$rootNode) {
if ($rootNode->ownerDocument == null) {
unset($this->ownerDocument);
$this->ownerDocument = null;
}
else {
$this->ownerDocument =& $rootNode->ownerDocument;
}
$total = $this->childCount;
for ($i = 0; $i < $total; $i++) {
$this->childNodes[$i]->setOwnerDocument($rootNode);
}
} //setOwnerDocument
/**
* Tests whether a value is null, and if so, returns a default value
* @param mixed The value to be tested
* @param mixed The default value
* @return mixed The specified value, or the default value if null
*/
function &nvl(&$value,$default) {
if (is_null($value)) return $default;
return $value;
} //nvl
/**
* Retrieves an element or DOMIT_NodeList of elements corresponding to an Xpath-like expression.
* @abstract
* @param string The query pattern
* @param int If a single node is to be returned (rather than the entire NodeList) the index of that node
* @return mixed A NodeList or single node that matches the pattern
*/
function &getElementsByPath($pattern, $nodeIndex = 0) {
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Method getElementsByPath cannot be called by class ' . get_class($this)));
} //getElementsByPath
/**
* Retrieves an element or DOMIT_NodeList of elements corresponding to an Xpath-like attribute expression (NOT YET IMPLEMENTED!)
* @abstract
* @param string The query pattern
* @param int If a single node is to be returned (rather than the entire NodeList) the index of that node
* @return mixed A NodeList or single node that matches the pattern
*/
function &getElementsByAttributePath($pattern, $nodeIndex = 0) {
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Method getElementsByAttributePath cannot be called by class ' . get_class($this)));
} //getElementsByAttributePath
/**
* Adds all child nodes of the specified nodeType to the NodeList
* @abstract
* @param Object The NodeList collection
* @param string The nodeType of matching nodes
*/
function getTypedNodes(&$nodeList, $type) {
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Method getTypedNodes cannot be called by class ' . get_class($this)));
} //getTypedNodes
/**
* Adds all child nodes of the specified nodeValue to the NodeList
* @abstract
* @param Object The NodeList collection
* @param string The nodeValue of matching nodes
*/
function getValuedNodes(&$nodeList, $value) {
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Method getValuedNodes cannot be called by class ' . get_class($this)));
} //getValuedNodes
/**
* Returns the concatented text of the current node and its children
* @return string The concatented text of the current node and its children
*/
function getText() {
return $this->nodeValue;
} //getText
/**
* Indicates whether the specified feature is supported by the DOM implementation and this node
* @param string The feature
* @param string The version of the DOM implementation
* @return boolean True if the specified feature is supported
*/
function isSupported($feature, $version = null) {
//don't worry about parsing based on version at this point in time;
//the only feature that is supported is 'XML'...
if (($version == '1.0') || ($version == '2.0') || ($version == null)) {
if (strtoupper($feature) == 'XML') {
return true;
}
}
return false;
} //isSupported
/**
* Formats a string for presentation as HTML
* @param string The string to be formatted
* @param boolean True if the string is to be sent directly to output
* @return string The HTML formatted string
*/
function forHTML($str, $doPrint = false) {
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php');
return DOMIT_Utilities::forHTML($str, $doPrint);
} //forHTML
/**
* Generates an array representation of the node and its children
* @abstract
* @return Array A representation of the node and its children
*/
function toArray() {
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Method toArray cannot be called by class ' . get_class($this)));
} //toArray
/**
* A node event that can be set to fire upon document loading, used for node initialization
* @abstract
*/
function onLoad() {
//you can override this method if you subclass any of the
//DOMIT_Nodes. It's a way of performing
//initialization of your subclass as soon as the document
//has been loaded (as opposed to as soon as the current node
//has been instantiated).
} //onLoad
/**
* Clears previousSibling, nextSibling, and parentNode references from a node that has been removed
*/
function clearReferences() {
if ($this->previousSibling != null) {
unset($this->previousSibling);
$this->previousSibling = null;
}
if ($this->nextSibling != null) {
unset($this->nextSibling);
$this->nextSibling = null;
}
if ($this->parentNode != null) {
unset($this->parentNode);
$this->parentNode = null;
}
} //clearReferences
/**
* Removes the node from the document
*/
function delete () {
if ($this->parentNode != null) {
$this->parentNode->removeChild($node);
}
} //delete
/**
* Generates a normalized (formatted for readability) representation of the node and its children
* @param boolean True if HTML readable output is desired
* @param boolean True if illegal xml characters in text nodes and attributes should be converted to entities
* @return string The formatted string representation
*/
function toNormalizedString($htmlSafe = false, $subEntities = false) {
//require this file for generating a normalized (readable) xml string representation
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php');
global $DOMIT_defined_entities_flip;
$result = DOMIT_Utilities::toNormalizedString($this, $subEntities, $DOMIT_defined_entities_flip);
if ($htmlSafe) $result = $this->forHTML($result);
return $result;
} //toNormalizedString
} //DOMIT_Node
/**
* A parent class for nodes which possess child nodes
*
* @package domit-xmlparser
* @subpackage domit-xmlparser-main
* @author John Heinstein <johnkarl@nbnet.nb.ca>
*/
class DOMIT_ChildNodes_Interface extends DOMIT_Node {
/**
* Raises error if abstract class is directly instantiated
*/
function DOMIT_ChildNodes_Interface() {
DOMIT_DOMException::raiseException(DOMIT_ABSTRACT_CLASS_INSTANTIATION_ERR,
'Cannot instantiate abstract class DOMIT_ChildNodes_Interface');
} //DOMIT_ChildNodes_Interface
/**
* Appends a node to the childNodes list of the current node
* @param Object The node to be appended
* @return Object The appended node
*/
function &appendChild(&$child) {
if ($child->nodeType == DOMIT_ATTRIBUTE_NODE) {
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Cannot add a node of type ' . get_class($child) . ' using appendChild'));
}
else if ($child->nodeType == DOMIT_DOCUMENT_FRAGMENT_NODE) {
$total = $child->childCount;
for ($i = 0; $i < $total; $i++) {
$currChild =& $child->childNodes[$i];
$this->appendChild($currChild);
}
}
else {
if (!($this->hasChildNodes())) {
$this->childNodes[0] =& $child;
$this->firstChild =& $child;
}
else {
//remove $child if it already exists
$index = $this->getChildNodeIndex($this->childNodes, $child);
if ($index != -1) {
$this->removeChild($child);
}
//append child
$numNodes = $this->childCount;
//BB: was bug auto-created wrong childnodes[-1]: added IF
if ($numNodes > 0) {
$prevSibling =& $this->childNodes[($numNodes - 1)];
}
$this->childNodes[$numNodes] =& $child;
//set next and previous relationships
//BB: added this line and the else part to finish correcting bug
if (isset( $prevSibling )) {
$child->previousSibling =& $prevSibling;
$prevSibling->nextSibling =& $child;
} else {
unset( $child->previousSibling );
$child->previousSibling = null;
$this->firstChild =& $child;
}
}
}
$this->lastChild =& $child;
$child->parentNode =& $this;
unset($child->nextSibling);
$child->nextSibling = null;
$child->setOwnerDocument($this);
$this->childCount++;
return $child;
} //appendChild
/**
* Inserts a node to the childNodes list of the current node
* @param Object The node to be inserted
* @param Object The node before which the insertion is to occur
* @return Object The inserted node
*/
function &insertBefore(&$newChild, &$refChild) {
if ($newChild->nodeType == DOMIT_ATTRIBUTE_NODE) {
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Cannot add a node of type ' . get_class($newChild) . ' using insertBefore'));
}
if (($refChild->nodeType == DOMIT_DOCUMENT_NODE) ||
//($refChild->parentNode->nodeType == DOMIT_DOCUMENT_NODE) ||
($refChild->parentNode == null)) {
DOMIT_DOMException::raiseException(DOMIT_NOT_FOUND_ERR,
'Reference child not present in the child nodes list.');
}
//if reference child is also the node to be inserted
//leave the document as is and don't raise an exception
if ($refChild->uid == $newChild->uid) {
return $newChild;
}
//if $newChild is a DocumentFragment,
//loop through and insert each node separately
if ($newChild->nodeType == DOMIT_DOCUMENT_FRAGMENT_NODE) {
$total = $newChild->childCount;
for ($i = 0; $i < $total; $i++) {
$currChild =& $newChild->childNodes[$i];
$this->insertBefore($currChild, $refChild);
}
return $newChild;
}
//remove $newChild if it already exists
$index = $this->getChildNodeIndex($this->childNodes, $newChild);
if ($index != -1) {
$this->removeChild($newChild);
}
//find index of $refChild in childNodes
$index = $this->getChildNodeIndex($this->childNodes, $refChild);
if ($index != -1) {
//reset sibling chain
if ($refChild->previousSibling != null) {
$refChild->previousSibling->nextSibling =& $newChild;
$newChild->previousSibling =& $refChild->previousSibling;
}
else {
$this->firstChild =& $newChild;
if ($newChild->previousSibling != null) {
unset($newChild->previousSibling);
$newChild->previousSibling = null;
}
}
$newChild->parentNode =& $refChild->parentNode;
$newChild->nextSibling =& $refChild;
$refChild->previousSibling =& $newChild;
//add node to childNodes
$i = $this->childCount;
while ($i >= 0) {
if ($i > $index) {
$this->childNodes[$i] =& $this->childNodes[($i - 1)];
}
else if ($i == $index) {
$this->childNodes[$i] =& $newChild;
}
$i--;
}
$this->childCount++;
}
else {
$this->appendChild($newChild);
}
$newChild->setOwnerDocument($this);
return $newChild;
} //insertBefore
/**
* Replaces a node with another
* @param Object The new node
* @param Object The old node
* @return Object The new node
*/
function &replaceChild(&$newChild, &$oldChild) {
if ($newChild->nodeType == DOMIT_ATTRIBUTE_NODE) {
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Cannot add a node of type ' . get_class($newChild) . ' using replaceChild'));
}
else if ($newChild->nodeType == DOMIT_DOCUMENT_FRAGMENT_NODE) { //if $newChild is a DocumentFragment
//replace the first node then loop through and insert each node separately
$total = $newChild->childCount;
if ($total > 0) {
$newRef =& $newChild->lastChild;
$this->replaceChild($newRef, $oldChild);
for ($i = 0; $i < ($total - 1); $i++) {
$currChild =& $newChild->childNodes[$i];
$this->insertBefore($currChild, $newRef);
}
}
return $newChild;
}
else {
if ($this->hasChildNodes()) {
//remove $newChild if it already exists
$index = $this->getChildNodeIndex($this->childNodes, $newChild);
if ($index != -1) {
$this->removeChild($newChild);
}
//find index of $oldChild in childNodes
$index = $this->getChildNodeIndex($this->childNodes, $oldChild);
if ($index != -1) {
$newChild->ownerDocument =& $oldChild->ownerDocument;
$newChild->parentNode =& $oldChild->parentNode;
//reset sibling chain
if ($oldChild->previousSibling == null) {
unset($newChild->previousSibling);
$newChild->previousSibling = null;
}
else {
$oldChild->previousSibling->nextSibling =& $newChild;
$newChild->previousSibling =& $oldChild->previousSibling;
}
if ($oldChild->nextSibling == null) {
unset($newChild->nextSibling);
$newChild->nextSibling = null;
}
else {
$oldChild->nextSibling->previousSibling =& $newChild;
$newChild->nextSibling =& $oldChild->nextSibling;
}
$this->childNodes[$index] =& $newChild;
if ($index == 0) $this->firstChild =& $newChild;
if ($index == ($this->childCount - 1)) $this->lastChild =& $newChild;
$newChild->setOwnerDocument($this);
return $newChild;
}
}
DOMIT_DOMException::raiseException(DOMIT_NOT_FOUND_ERR,
('Reference node for replaceChild not found.'));
}
} //replaceChild
/**
* Removes a node from the childNodes list of the current node
* @param Object The node to be removed
* @return Object The removed node
*/
function &removeChild(&$oldChild) {
if ($this->hasChildNodes()) {
//find index of $oldChild in childNodes
$index = $this->getChildNodeIndex($this->childNodes, $oldChild);
if ($index != -1) {
//reset sibling chain
if (($oldChild->previousSibling != null) && ($oldChild->nextSibling != null)) {
$oldChild->previousSibling->nextSibling =& $oldChild->nextSibling;
$oldChild->nextSibling->previousSibling =& $oldChild->previousSibling;
}
else if (($oldChild->previousSibling != null) && ($oldChild->nextSibling == null)) {
$this->lastChild =& $oldChild->previousSibling;
unset($oldChild->previousSibling->nextSibling);
$oldChild->previousSibling->nextSibling = null;
}
else if (($oldChild->previousSibling == null) && ($oldChild->nextSibling != null)) {
unset($oldChild->nextSibling->previousSibling);
$oldChild->nextSibling->previousSibling = null;
$this->firstChild =& $oldChild->nextSibling;
}
else if (($oldChild->previousSibling == null) && ($oldChild->nextSibling == null)) {
unset($this->firstChild);
$this->firstChild = null;
unset($this->lastChild);
$this->lastChild = null;
}
$total = $this->childCount;
//remove node from childNodes
for ($i = 0; $i < $total; $i++) {
if ($i == ($total - 1)) {
array_splice($this->childNodes, $i, 1);
}
else if ($i >= $index) {
$this->childNodes[$i] =& $this->childNodes[($i + 1)];
}
}
$this->childCount--;
$oldChild->clearReferences();
return $oldChild;
}
}
DOMIT_DOMException::raiseException(DOMIT_NOT_FOUND_ERR,
('Target node for removeChild not found.'));
} //removeChild
/**
* Searches the element tree for an element with the specified attribute name and value.
* @param string The value of the attribute
* @param string The name of the attribute
* @param boolean True if the first found node is to be returned as a node instead of a nodelist
* @param boolean True if uid is to be considered an attribute
* @return object A NodeList of found elements, or null
*/
function &getElementsByAttribute($attrName = 'id', $attrValue = '',
$returnFirstFoundNode = false, $treatUIDAsAttribute = false) {
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_nodemaps.php');
$nodelist = new DOMIT_NodeList();
switch ($this->nodeType) {
case DOMIT_ELEMENT_NODE:
$this->_getElementsByAttribute($nodelist, $attrName, $attrValue,
$returnFirstFoundNode, $treatUIDAsAttribute);
break;
case DOMIT_DOCUMENT_NODE:
if ($this->documentElement != null) {
$this->documentElement->_getElementsByAttribute($nodelist,
$attrName, $attrValue, $returnFirstFoundNode, $treatUIDAsAttribute);
}
break;
}
if ($returnFirstFoundNode) {
if ($nodelist->getLength() > 0) {
return $nodelist->item(0);
}
else {
$null = null;
return $null;
}
}
else {
return $nodelist;
}
} //getElementsByAttribute
/**
* Searches the element tree for an element with the specified attribute name and value.
* @param object The node list of found elements
* @param string The value of the attribute
* @param string The name of the attribute
* @param boolean True if the first found node is to be returned as a node instead of a nodelist
* @param boolean True if uid is to be considered an attribute
* @param boolean True the node has been found
*/
function _getElementsByAttribute(&$nodelist, $attrName, $attrValue,
$returnFirstFoundNode, $treatUIDAsAttribute, $foundNode = false) {
if (!($foundNode && $returnFirstFoundNode)) {
if (($this->getAttribute($attrName) == $attrValue) ||
($treatUIDAsAttribute && ($attrName == 'uid') && ($this->uid == $attrValue))) {
$nodelist->appendNode($this);
$foundNode = true;
if ($returnFirstFoundNode) return;
}
$total = $this->childCount;
for ($i = 0; $i < $total; $i++) {
$currNode =& $this->childNodes[$i];
if ($currNode->nodeType == DOMIT_ELEMENT_NODE) {
$currNode->_getElementsByAttribute($nodelist,
$attrName, $attrValue, $returnFirstFoundNode,
$treatUIDAsAttribute, $foundNode);
}
}
}
} //_getElementsByAttribute
/**
* Performs an XPath query
* @param string The query pattern
* @return Object A NodeList containing the found nodes
*/
function &selectNodes($pattern, $nodeIndex = 0) {
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_xpath.php');
$xpParser = new DOMIT_XPath();
return $xpParser->parsePattern($this, $pattern, $nodeIndex);
} //selectNodes
/**
* Converts the childNodes array into a NodeList object
* @return Object A NodeList containing elements of the childNodes array
*/
function &childNodesAsNodeList() {
require_once('xml_domit_nodemaps.php');
$myNodeList = new DOMIT_NodeList();
$total = $this->childCount;
for ($i = 0; $i < $total; $i++) {
$myNodeList->appendNode($this->childNodes[$i]);
}
return $myNodeList;
} //childNodesAsNodeList
} //DOMIT_ChildNodes_Interface
/**
* A class representing the DOM Document
*
* @package domit-xmlparser
* @subpackage domit-xmlparser-main
* @author John Heinstein <johnkarl@nbnet.nb.ca>
*/
class DOMIT_Document extends DOMIT_ChildNodes_Interface {
/** @var Object The xml declaration processing instruction */
var $xmlDeclaration;
/** @var Object A reference to a DOMIT_DocType object */
var $doctype;
/** @var Object A reference to the root node of the DOM document */
var $documentElement;
/** @var string The parser used to process the DOM document, either "EXPAT" or "SAXY" */
var $parser;
/** @var Object A reference to the DOMIT_DOMImplementation object */
var $implementation;
/** @var boolean True if the DOM document has been modifed since being parsed (NOT YET IMPLEMENTED!) */
var $isModified;
/** @var boolean True if whitespace is to be preserved during parsing */
var $preserveWhitespace = false;
/** @var Array User defined translation table for XML entities; passed to SAXY */
var $definedEntities = array();
/** @var boolean If true, loadXML or parseXML will attempt to detect and repair invalid xml */
var $doResolveErrors = false;
/** @var boolean If true, elements tags will be rendered to string as <element></element> rather than <element/> */
var $doExpandEmptyElementTags = false;
/** @var array A list of exceptions to the empty element expansion rule */
var $expandEmptyElementExceptions = array();
/** @var boolean If true, namespaces will be processed */
var $isNamespaceAware = false;
/** @var int The error code returned by the SAX parser */
var $errorCode = 0;
/** @var string The error string returned by the SAX parser */
var $errorString = '';
/** @var object A reference to a http connection or proxy server, if one is required */
var $httpConnection = null;
/** @var boolean True if php_http_client_generic is to be used instead of PHP get_file_contents to retrieve xml data */
var $doUseHTTPClient = false;
/** @var array An array of namespacesURIs mapped to prefixes */
var $namespaceURIMap = array();
/**
* DOM Document constructor
*/
function DOMIT_Document() {
$this->_constructor();
$this->xmlDeclaration = null;
$this->doctype = null;
$this->documentElement = null;
$this->nodeType = DOMIT_DOCUMENT_NODE;
$this->nodeName = '#document';
$this->ownerDocument =& $this;
$this->parser = '';
$this->implementation = new DOMIT_DOMImplementation();
} //DOMIT_Document
/**
* Specifies whether DOMIT! will try to fix invalid XML before parsing begins
* @param boolean True if errors are to be resolved
*/
function resolveErrors($truthVal) {
$this->doResolveErrors = $truthVal;
} //resolveErrors
/**
* Specifies whether DOMIT! processes namespace information
* @param boolean True if namespaces are to be processed
*/
function setNamespaceAwareness($truthVal) {
$this->isNamespaceAware = $truthVal;
} //setNamespaceAwareness
/**
* Specifies whether DOMIT! preserves whitespace when parsing
* @param boolean True if whitespace is to be preserved
*/
function preserveWhitespace($truthVal) {
$this->preserveWhitespace = $truthVal;
} //preserveWhitespace
/**
* Specifies the parameters of the http conection used to obtain the xml data
* @param string The ip address or domain name of the connection
* @param string The path of the connection
* @param int The port that the connection is listening on
* @param int The timeout value for the connection
* @param string The user name, if authentication is required
* @param string The password, if authentication is required
*/
function setConnection($host, $path = '/', $port = 80, $timeout = 0, $user = null, $password = null) {
require_once(DOMIT_INCLUDE_PATH . 'php_http_client_generic.php');
$this->httpConnection = new php_http_client_generic($host, $path, $port, $timeout, $user, $password);
} //setConnection
/**
* Specifies basic authentication for an http connection
* @param string The user name
* @param string The password
*/
function setAuthorization($user, $password) {
$this->httpConnection->setAuthorization($user, $password);
} //setAuthorization
/**
* Specifies that a proxy is to be used to obtain the xml data
* @param string The ip address or domain name of the proxy
* @param string The path to the proxy
* @param int The port that the proxy is listening on
* @param int The timeout value for the connection
* @param string The user name, if authentication is required
* @param string The password, if authentication is required
*/
function setProxyConnection($host, $path = '/', $port = 80, $timeout = 0, $user = null, $password = null) {
require_once(DOMIT_INCLUDE_PATH . 'php_http_proxy.php');
$this->httpConnection = new php_http_proxy($host, $path, $port, $timeout, $user, $password);
} //setProxyConnection
/**
* Specifies basic authentication for the proxy
* @param string The user name
* @param string The password
*/
function setProxyAuthorization($user, $password) {
$this->httpConnection->setProxyAuthorization($user, $password);
} //setProxyAuthorization
/**
* Specifies whether an HTTP client should be used to establish a connection
* @param boolean True if an HTTP client is to be used to establish the connection
*/
function useHTTPClient($truthVal) {
$this->doUseHTTPClient = $truthVal;
} //useHTTPClient
/**
* Returns the error code from the underlying SAX parser
* @return int The error code
*/
function getErrorCode() {
return $this->errorCode;
} //getErrorCode
/**
* Returns the error string from the underlying SAX parser
* @return string The error string
*/
function getErrorString() {
return $this->errorString;
} //getErrorString
/**
* Specifies whether elements tags will be rendered to string as <element></element> rather than <element/>
* @param boolean True if the expanded form is to be used
* @param mixed An array of tag names that should be excepted from expandEmptyElements rule (optional)
*/
function expandEmptyElementTags($truthVal, $expandEmptyElementExceptions = false) {
$this->doExpandEmptyElementTags = $truthVal;
if (is_array($expandEmptyElementExceptions)) {
$this->expandEmptyElementExceptions = $expandEmptyElementExceptions;
}
} //expandEmptyElementTags
/**
* Set the specified node as document element
* @param Object The node that is to become document element
* @return Object The new document element
*/
function &setDocumentElement(&$node) {
if ($node->nodeType == DOMIT_ELEMENT_NODE) {
if ($this->documentElement == null) {
parent::appendChild($node);
}
else {
parent::replaceChild($node, $this->documentElement);
}
$this->documentElement =& $node;
}
else {
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Cannot add a node of type ' . get_class($node) . ' as a Document Element.'));
}
return $node;
} //setDocumentElement
/**
* Imports a node (and optionally its children) from another DOM Document
* @param object A reference to the node to be imported
* @param boolean True if the children of the imported node are also to be imported
* @return object The imported node (and, if specified, its children)
*/
function &importNode(&$importedNode, $deep = true) {
$parentNode = null;
return $this->_importNode($parentNode, $importedNode, $deep);
} //importNode
/**
* Imports a node (and optionally its children) from another DOM Document
* @param object A reference to the parent of the node to be imported
* @param object A reference to the node to be imported
* @param boolean True if the children of the imported node are also to be imported
* @return object The imported node if it is the top level node, otherwise null
*/
function &_importNode(&$parentNode, &$sourceNode, $deep) {
$hasChildren = false;
switch ($sourceNode->nodeType) {
case DOMIT_ELEMENT_NODE:
$hasChildren = true;
if ($this->isNamespaceAware) {
$importedNode =& $this->createElementNS($sourceNode->namespaceURI,
($sourceNode->prefix . ":" . $sourceNode->localName));
}
else {
$importedNode =& $this->createElement($sourceNode->nodeName);
}
$attrNodes =& $sourceNode->attributes;
$total = $attrNodes->getLength();
for ($i = 0; $i < $total; $i++) {
$attrNode =& $attrNodes->item($i);
if ($this->isNamespaceAware) {
$importedNode->setAttributeNS($attrNode->namespaceURI,
($attrNode->prefix . ":" . $attrNode->localName), $attrNode->nodeValue);
}
else {
$importedNode->setAttribute($attrNode->nodeName, $attrNode->nodeValue);
}
}
break;
case DOMIT_ATTRIBUTE_NODE:
if ($this->isNamespaceAware) {
$importedNode =& $this->createAttributeNS($sourceNode->namespaceURI,
($sourceNode->prefix . ":" . $sourceNode->localName));
}
else {
$importedNode =& $this->createAttribute($sourceNode->nodeValue);
}
break;
case DOMIT_TEXT_NODE:
$importedNode =& $this->createTextNode($sourceNode->nodeValue);
break;
case DOMIT_CDATA_SECTION_NODE:
$importedNode =& $this->createCDATASection($sourceNode->nodeValue);
break;
case DOMIT_COMMENT_NODE:
$importedNode =& $this->createComment($sourceNode->nodeValue);
break;
case DOMIT_DOCUMENT_FRAGMENT_NODE:
$hasChildren = true;
$importedNode =& $this->createDocumentFragment();
break;
case DOMIT_PROCESSING_INSTRUCTION_NODE:
$importedNode =& $this->createProcessingInstruction($sourceNode->nodeName,
$sourceNode->nodeValue);
break;
case DOMIT_DOCUMENT_NODE:
case DOMIT_DOCUMENT_TYPE_NODE:
DOMIT_DOMException::raiseException(DOMIT_NOT_SUPPORTED_ERR,
('Method importNode cannot be called by class ' . get_class($this)));
break;
}
if ($hasChildren && $deep) {
$total = $sourceNode->childCount;
for ($i = 0; $i < $total; $i++) {
$importedNode->appendChild(
$this->_importNode($importedNode, $sourceNode->childNodes[$i], $deep));
}
}
return $importedNode;
} //_importNode
/**
* Appends a node to the childNodes list of the current node
* @param Object The node to be appended
* @return Object The appended node
*/
function &appendChild(&$node) {
switch ($node->nodeType) {
case DOMIT_ELEMENT_NODE:
if ($this->documentElement == null) {
parent::appendChild($node);
$this->setDocumentElement($node);
}
else {
//error thrown if documentElement already exists!
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Cannot have more than one root node (documentElement) in a DOMIT_Document.'));
}
break;
case DOMIT_PROCESSING_INSTRUCTION_NODE:
case DOMIT_COMMENT_NODE:
parent::appendChild($node);
break;
case DOMIT_DOCUMENT_TYPE_NODE:
if ($this->doctype == null) {
parent::appendChild($node);
}
else {
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Cannot have more than one doctype node in a DOMIT_Document.'));
}
break;
case DOMIT_DOCUMENT_FRAGMENT_NODE:
$total = $node->childCount;
for ($i = 0; $i < $total; $i++) {
$currChild =& $node->childNodes[$i];
$this->appendChild($currChild);
}
break;
default:
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Cannot add a node of type ' . get_class($node) . ' to a DOMIT_Document.'));
}
return $node;
} //appendChild
/**
* Replaces a node with another
* @param Object The new node
* @param Object The old node
* @return Object The new node
*/
function &replaceChild(&$newChild, &$oldChild) {
if ($this->nodeType == DOMIT_DOCUMENT_FRAGMENT_NODE) {
$total = $newChild->childCount;
if ($total > 0) {
$newRef =& $newChild->lastChild;
$this->replaceChild($newRef, $oldChild);
for ($i = 0; $i < ($total - 1); $i++) {
$currChild =& $newChild->childNodes[$i];
parent::insertBefore($currChild, $newRef);
}
}
}
else {
if (($this->documentElement != null) && ($oldChild->uid == $this->documentElement->uid)) {
if ($newChild->nodeType == DOMIT_ELEMENT_NODE) {
//replace documentElement with new node
$this->setDocumentElement($newChild);
}
else {
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Cannot replace Document Element with a node of class ' . get_class($newChild)));
}
}
else {
switch ($newChild->nodeType) {
case DOMIT_ELEMENT_NODE:
if ($this->documentElement != null) {
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Cannot have more than one root node (documentElement) in a DOMIT_Document.'));
}
else {
parent::replaceChild($newChild, $oldChild);
}
break;
case DOMIT_PROCESSING_INSTRUCTION_NODE:
case DOMIT_COMMENT_NODE:
parent::replaceChild($newChild, $oldChild);
break;
case DOMIT_DOCUMENT_TYPE_NODE:
if ($this->doctype != null) {
if ($this->doctype->uid == $oldChild->uid) {
parent::replaceChild($newChild, $oldChild);
}
else {
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Cannot have more than one doctype node in a DOMIT_Document.'));
}
}
else {
parent::replaceChild($newChild, $oldChild);
}
break;
default:
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Nodes of class ' . get_class($newChild) . ' cannot be children of a DOMIT_Document.'));
}
}
}
return $newChild;
} //replaceChild
/**
* Inserts a node to the childNodes list of the current node
* @param Object The node to be inserted
* @param Object The node before which the insertion is to occur
* @return Object The inserted node
*/
function &insertBefore(&$newChild, &$refChild) {
$type = $newChild->nodeType;
if ($this->nodeType == DOMIT_DOCUMENT_FRAGMENT_NODE) {
$total = $newChild->childCount;
for ($i = 0; $i < $total; $i++) {
$currChild =& $newChild->childNodes[$i];
$this->insertBefore($currChild, $refChild);
}
}
else if ($type == DOMIT_ELEMENT_NODE) {
if ($this->documentElement == null) {
parent::insertBefore($newChild, $refChild);
$this->setDocumentElement($newChild);
}
else {
//error thrown if documentElement already exists!
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Cannot have more than one root node (documentElement) in a DOMIT_Document.'));
}
}
else if ($type == DOMIT_PROCESSING_INSTRUCTION_NODE) {
parent::insertBefore($newChild, $refChild);
}
else if ($type == DOMIT_DOCUMENT_TYPE_NODE) {
if ($this->doctype == null) {
parent::insertBefore($newChild, $refChild);
}
else {
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Cannot have more than one doctype node in a DOMIT_Document.'));
}
}
else {
DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,
('Cannot insert a node of type ' . get_class($newChild) . ' to a DOMIT_Document.'));
}
return $newChild;
} //insertBefore
/**
* Removes a node from the childNodes list of the current node
* @param Object The node to be removed
* @return Object The removed node
*/
function &removeChild(&$oldChild) {
if ($this->nodeType == DOMIT_DOCUMENT_FRAGMENT_NODE) {
$total = $oldChild->childCount;
for ($i = 0; $i < $total; $i++) {
$currChild =& $oldChild->childNodes[$i];
$this->removeChild($currChild);
}
}
else {
if (($this->documentElement != null) && ($oldChild->uid == $this->documentElement->uid)) {
parent::removeChild($oldChild);
$this->documentElement = null;
}
else {
parent::removeChild($oldChild);
}
}
$oldChild->clearReferences();
return $oldChild;
} //removeChild
/**
* Creates a new DOMIT_DocumentFragment node
* @return Object The new document fragment node
*/
function &createDocumentFragment() {
$node = new DOMIT_DocumentFragment();
$node->ownerDocument =& $this;
return $node;
} //createDocumentFragment
/**
* Creates a new DOMIT_Attr node
* @param string The name of the attribute
* @return Object The new attribute node
*/
function &createAttribute($name) {
$node = new DOMIT_Attr($name);
return $node;
} //createAttribute
/**
* Creates a new DOMIT_Attr node (namespace aware)
* @param string The namespaceURI of the attribute
* @param string The qualifiedName of the attribute
* @return Object The new attribute node
*/
function &createAttributeNS($namespaceURI, $qualifiedName) {
$node = new DOMIT_Attr($qualifiedName);
$node->namespaceURI = $namespaceURI;
$colonIndex = strpos($qualifiedName, ":");
if ($colonIndex !== false) {
$node->prefix = substr($qualifiedName, 0, $colonIndex);
$node->localName = substr($qualifiedName, ($colonIndex + 1));
}
else {
$node->prefix = '';
$node->localName = $qualifiedName;
}
return $node;
} //createAttributeNS
/**
* Creates a new DOMIT_Element node
* @param string The tag name of the element
* @return Object The new element
*/
function &createElement($tagName) {
$node = new DOMIT_Element($tagName);
$node->ownerDocument =& $this;
return $node;
} //createElement
/**
* Creates a new DOMIT_Element node (namespace aware)
* @param string The namespaceURI of the element
* @param string The qualifiedName of the element
* @return Object The new element
*/
function &createElementNS($namespaceURI, $qualifiedName) {
$node = new DOMIT_Element($qualifiedName);
$colonIndex = strpos($qualifiedName, ":");
if ($colonIndex !== false) {
$node->prefix = substr($qualifiedName, 0, $colonIndex);
$node->localName = substr($qualifiedName, ($colonIndex + 1));
}
else {
$node->prefix = '';
$node->localName = $qualifiedName;
}
$node->namespaceURI = $namespaceURI;
$node->ownerDocument =& $this;
return $node;
} //createElementNS
/**
* Creates a new DOMIT_Text node
* @param string The text of the node
* @return Object The new text node
*/
function &createTextNode($data) {
$node = new DOMIT_TextNode($data);
$node->ownerDocument =& $this;
return $node;
} //createTextNode
/**
* Creates a new DOMIT_CDataSection node
* @param string The text of the CDATASection
* @return Object The new CDATASection node
*/
function &createCDATASection($data) {
$node = new DOMIT_CDATASection($data);
$node->ownerDocument =& $this;
return $node;
} //createCDATASection
/**
* Creates a new DOMIT_Comment node
* @param string The comment text
* @return Object The new comment node
*/
function &createComment($text) {
$node = new DOMIT_Comment($text);
$node->ownerDocument =& $this;
return $node;
} //createComment
/**
* Creates a new DOMIT_ProcessingInstruction node
* @param string The target of the processing instruction
* @param string The data of the processing instruction
* @return Object The new processing instruction node
*/
function &createProcessingInstruction($target, $data) {
$node = new DOMIT_ProcessingInstruction($target, $data);
$node->ownerDocument =& $this;
return $node;
} //createProcessingInstruction
/**
* Retrieves a NodeList of child elements with the specified tag name
* @param string The matching element tag name
* @return Object A NodeList of found elements
*/
function &getElementsByTagName($tagName) {
$nodeList = new DOMIT_NodeList();
if ($this->documentElement != null) {
$this->documentElement->getNamedElements($nodeList, $tagName);
}
return $nodeList;
} //getElementsByTagName
/**
* Retrieves a NodeList of child elements with the specified namespaceURI and localName
* @param string The matching namespaceURI
* @param string The matching localName
* @return Object A NodeList of found elements
*/
function &getElementsByTagNameNS($namespaceURI, $localName) {
$nodeList = new DOMIT_NodeList();
if ($this->documentElement != null) {
$this->documentElement->getNamedElementsNS($nodeList, $namespaceURI, $localName);
}
return $nodeList;
} //getElementsByTagNameNS
/**
* Returns the element whose ID is given by elementId.
* @param string The id of the matching element
* @param boolean True if XML spec is to be strictly adhered to (only attributes xml:id are considered valid)
* @return Object The found element or null
*/
function &getElementByID($elementID, $isStrict = true) {
if ($this->isNamespaceAware) {
if ($this->documentElement != null) {
$targetAttrNode =& $this->documentElement->_getElementByID($elementID, $isStrict);
return $targetAttrNode->ownerElement;
}
$null = null;
return $null;
}
else {
DOMIT_DOMException::raiseException(DOMIT_INVALID_ACCESS_ERR,
'Namespace awareness must be enabled to use method getElementByID');
}
} //getElementByID
/**
* Retrieves an element or DOMIT_NodeList of elements corresponding to an Xpath-like expression.
* @param string The query pattern
* @param int If a single node is to be returned (rather than the entire NodeList) the index of that node
* @return mixed A NodeList or single node that matches the pattern
*/
function &getElementsByPath($pattern, $nodeIndex = 0) {
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_getelementsbypath.php');
$gebp = new DOMIT_GetElementsByPath();
$myResponse =& $gebp->parsePattern($this, $pattern, $nodeIndex);
return $myResponse;
} //getElementsByPath
/**
* Retrieves an element or DOMIT_NodeList of elements corresponding to an Xpath-like attribute expression (NOT YET IMPLEMENTED!)
* @param string The query pattern
* @param int If a single node is to be returned (rather than the entire NodeList) the index of that node
* @return mixed A NodeList or single node that matches the pattern
*/
function &getElementsByAttributePath($pattern, $nodeIndex = 0) {
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_getelementsbypath.php');
$gabp = new DOMIT_GetElementsByAttributePath();
$myResponse =& $gabp->parsePattern($this, $pattern, $nodeIndex);
return $myResponse;
} //getElementsByAttributePath
/**
* Retrieves all child nodes of the specified nodeType
* @param string The nodeType of matching nodes
* @param Object The root node of the search
* @return Object A NodeList containing found nodes
*/
function &getNodesByNodeType($type, &$contextNode) {
$nodeList = new DOMIT_NodeList();
if (($type == DOMIT_DOCUMENT_NODE) || ($contextNode->nodeType == DOMIT_DOCUMENT_NODE)){
$nodeList->appendNode($this);
}
else if ($contextNode->nodeType == DOMIT_ELEMENT_NODE) {
$contextNode->getTypedNodes($nodeList, $type);
}
else if ($contextNode->uid == $this->uid) {
if ($this->documentElement != null) {
if ($type == DOMIT_ELEMENT_NODE) {
$nodeList->appendNode($this->documentElement);
}
$this->documentElement->getTypedNodes($nodeList, $type);
}
}
return $nodeList;
} //getNodesByNodeType
/**
* Retrieves all child nodes of the specified nodeValue
* @param string The nodeValue of matching nodes
* @param Object The root node of the search
* @return Object A NodeList containing found nodes
*/
function &getNodesByNodeValue($value, &$contextNode) {
$nodeList = new DOMIT_NodeList();
if ($contextNode->uid == $this->uid) {
if ($this->nodeValue == $value) {
$nodeList->appendNode($this);
}
}
if ($this->documentElement != null) {
$this->documentElement->getValuedNodes($nodeList, $value);
}
return $nodeList;
} //getNodesByNodeValue
/**
* Parses an xml string
* @param string The xml text to be parsed
* @param boolean True if SAXY is to be used instead of Expat
* @param boolean False if CDATA Section are to be generated as Text nodes
* @param boolean True if onLoad is to be called on each node after parsing
* @return boolean True if parsing is successful
*/
function parseXML($xmlText, $useSAXY = true, $preserveCDATA = true, $fireLoadEvent = false) {
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php');
if ($this->doResolveErrors) {
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_doctor.php');
$xmlText = DOMIT_Doctor::fixAmpersands($xmlText);
}
if (DOMIT_Utilities::validateXML($xmlText)) {
$domParser = new DOMIT_Parser();
if ($useSAXY || (!function_exists('xml_parser_create'))) {
//use SAXY parser to populate xml tree
$this->parser = 'SAXY';
$success = $domParser->parseSAXY($this, $xmlText, $preserveCDATA, $this->definedEntities);
}
else {
//use Expat parser to populate xml tree
$this->parser = 'EXPAT';
$success = $domParser->parse($this, $xmlText, $preserveCDATA);
}
if ($fireLoadEvent && ($this->documentElement != null)) $this->load($this->documentElement);
return $success;
}
else {
return false;
}
} //parseXML
/**
* Parses an xml file
* @param string The xml file to be parsed
* @param boolean True if SAXY is to be used instead of Expat
* @param boolean False if CDATA Section are to be generated as Text nodes
* @param boolean True if onLoad is to be called on each node after parsing
* @return boolean True if parsing is successful
*/
function loadXML($filename, $useSAXY = true, $preserveCDATA = true, $fireLoadEvent = false) {
$xmlText = $this->getTextFromFile($filename);
return $this->parseXML($xmlText, $useSAXY, $preserveCDATA, $fireLoadEvent);
} //loadXML
/**
* Establishes a connection, given an url
* @param string The url of the data
*/
function establishConnection($url) {
require_once(DOMIT_INCLUDE_PATH . 'php_http_client_generic.php');
$host = php_http_connection::formatHost($url);
$host = substr($host, 0, strpos($host, '/'));
$this->setConnection($host);
} //establishConnection
/**
* Retrieves text from a file
* @param string The file path
* @return string The text contained in the file
*/
function getTextFromFile($filename) {
if ($this->doUseHTTPClient && (substr($filename, 0, 5) == 'http:')) {
$this->establishConnection($filename);
}
if ($this->httpConnection != null) {
$response =& $this->httpConnection->get($filename);
$this->httpConnection->disconnect();
return $response->getResponse();
}
else if (function_exists('file_get_contents')) {
//if (file_exists($filename)) {
return file_get_contents($filename);
//}
}
else {
require_once(DOMIT_INCLUDE_PATH . 'php_file_utilities.php');
$fileContents =& php_file_utilities::getDataFromFile($filename, 'r');
return $fileContents;
}
return '';
} //getTextFromFile
/**
* Saves the current DOM document as an xml file
* @param string The path of the xml file
* @param boolean True if xml text is to be normalized before saving
* @return boolean True if save is successful
*/
function saveXML($filename, $normalized = false) {
if ($normalized) {
$stringRep = $this->toNormalizedString(false, true);
}
else {
$stringRep = $this->toString(false, true);
}
return $this->saveTextToFile($filename, $stringRep);
} //saveXML
/**
* Saves text to a file
* @param string The file path
* @param string The text to be saved
* @return boolean True if the save is successful
*/
function saveTextToFile($filename, $text) {
if (function_exists('file_put_contents')) {
file_put_contents($filename, $text);
}
else {
require_once(DOMIT_INCLUDE_PATH . 'php_file_utilities.php');
php_file_utilities::putDataToFile($filename, $text, 'w');
}
return (file_exists($filename) && is_writable($filename));
} //saveTextToFile
/**
* Indicates the SAX parser used to parse the current document
* @return string Either "SAXY" or "EXPAT"
*/
function parsedBy() {
return $this->parser;
} //parsedBy
/**
* Returns the concatented text of the current node and its children
* @return string The concatented text of the current node and its children
*/
function getText() {
if ($this->documentElement != null) {
$root =& $this->documentElement;
return $root->getText();
}
return '';
} //getText
/**
* Returns a doctype object
* @return mixed The doctype object, or null if none exists
*/
function getDocType() {
return $this->doctype;
} //getDocType
/**
* Returns the xml declaration processing instruction
* @return mixed The xml declaration processing instruction, or null if none exists
*/
function getXMLDeclaration() {
return $this->xmlDeclaration;
} //getXMLDeclaration
/**
* Returns a reference to the DOMIT_DOMImplementation object
* @return Object A reference to the DOMIT_DOMImplementation object
*/
function &getDOMImplementation() {
return $this->implementation;
} //getDOMImplementation
/**
* Manages the firing of the onLoad() event
* @param Object The parent node of the current recursion
*/
function load(&$contextNode) {
$total = $contextNode->childCount;
for ($i = 0; $i < $total; $i++) {
$currNode =& $contextNode->childNodes[$i];
$currNode->ownerDocument->load($currNode);
}
$contextNode->onLoad();
} //load
/**
* Returns the current version of DOMIT!
* @return Object The current version of DOMIT!
*/
function getVersion() {
return DOMIT_VERSION;
} //getVersion
/**
* Appends an array of entity mappings to the existing translation table
*
* Intended mainly to facilitate the conversion of non-ASCII entities into equivalent characters
*
* @param array A list of entity mappings in the format: array('&' => '&');
*/
function appendEntityTranslationTable($table) {
$this->definedEntities = $table;
global $DOMIT_defined_entities_flip;
$DOMIT_defined_entities_flip = array_flip($table);
} //appendEntityTranslationTable
/**
* Generates an array representation of the node and its children
* @return Array A representation of the node and its children
*/
function toArray() {
$arReturn = array($this->nodeName => array());
$total = $this->childCount;
for ($i = 0; $i < $total; $i++) {
$arReturn[$this->nodeName][$i] = $this->childNodes[$i]->toArray();
}
return $arReturn;
} //toArray
/**
* Copies a node and/or its children
* @param boolean True if all child nodes are also to be cloned
* @return Object A copy of the node and/or its children
*/
function &cloneNode($deep = false) {
$className = get_class($this);
$clone = new $className($this->nodeName);
if ($deep) {
$total = $this->childCount;
for ($i = 0; $i < $total; $i++) {
$currentChild =& $this->childNodes[$i];
$clone->appendChild($currentChild->cloneNode($deep));
if ($currentChild->nodeType == DOMIT_DOCUMENT_TYPE_NODE) {
$clone->doctype =& $clone->childNodes[$i];
}
if (($currentChild->nodeType == DOMIT_PROCESSING_INSTRUCTION_NODE) &&
($currentChild->getTarget() == 'xml')) {
$clone->xmlDeclaration =& $clone->childNodes[$i];
}
}
}
return $clone;
} //cloneNode
/**
* Generates a string representation of the node and its children
* @param boolean True if HTML readable output is desired
* @param boolean True if illegal xml characters in text nodes and attributes should be converted to entities
* @return string The string representation
*/
function toString($htmlSafe = false, $subEntities = false) {
$result = '';
$total = $this->childCount;
for ($i = 0; $i < $total; $i++) {
$result .= $this->childNodes[$i]->toString(false, $subEntities);
}
if ($htmlSafe) $result = $this->forHTML($result);
return $result;
} //toString
} //DOMIT_Document
/**
* A class representing the DOM Element
*
* @package domit-xmlparser
* @subpackage domit-xmlparser-main
* @author John Heinstein <johnkarl@nbnet.nb.ca>
*/
class DOMIT_Element extends DOMIT_ChildNodes_Interface {
/** @var array An array of namespacesURIs mapped to prefixes */
var $namespaceURIMap = array();
/**
* DOM Element constructor
* @param string The tag name of the element
*/
function DOMIT_Element($tagName) {
$this->_constructor();
$this->nodeType = DOMIT_ELEMENT_NODE;
$this->nodeName = $tagName;
$this->attributes = new DOMIT_NamedNodeMap_Attr();
$this->childNodes = array();
} //DOMIT_Element
/**
* Returns the tag name of the element
* @return string The tag name of the element
*/
function getTagName() {
return $this->nodeName;
} //getTagName
/**
* Adds elements with the specified tag name to a NodeList collection
* @param Object The NodeList collection
* @param string The tag name of matching elements
*/
function getNamedElements(&$nodeList, $tagName) {
if (($this->nodeName == $tagName) || ($tagName == '*')) {
$nodeList->appendNode($this);
}
$total = $this->childCount;
for ($i = 0; $i < $total; $i++) {
$this->childNodes[$i]->getNamedElements($nodeList, $tagName);
}
} //getNamedElements
/**
* Creates an xmlns declaration at the current element
* @param array An array of namespace declarations in the scope of the current element
*/
function declareNamespace($localname, $value) {
//namespace URI for xmlns attribute is: http://www.w3.org/2000/xmlns/
$this->setAttributeNS(DOMIT_XMLNS_NAMESPACE, ('xmlns:' . $localname), $value);
//add to local namespaceURI map
$this->namespaceURIMap[$value] = $localname;
} //declareNamespace
/**
* Creates a default xmlns declaration at the current element
* @param array An array of namespace declarations in the scope of the current element
*/
function declareDefaultNamespace($value) {
//namespace URI for xmlns attribute is: http://www.w3.org/2000/xmlns/
$this->setAttributeNS(DOMIT_XMLNS_NAMESPACE, 'xmlns', $value);
//add to local namespaceURI map
$this->namespaceURIMap[$value] = 'xmlns';
} //declareDefaultNamespace
/**
* Returns an array of namespace declarations in the scope of the current element
* @return array An array of namespace declarations in the scope of the current element
*/
function &getNamespaceDeclarationsInScope() {
$nsMap = array();
return $this->_getNameSpaceDeclarationsInScope($nsMap);
} //getNamespacesInScope
/**
* Returns an array of namespace declarations in the scope of the current element
* @return array An array of namespace declarations in the scope of the current element
*/
function &_getNamespaceDeclarationsInScope(&$nsMap) {
//grab local xmlns declarations if not already present
foreach ($this->namespaceURIMap as $key => $value) {
if (!isset($nsMap[$key])) {
$nsMap[$key] = $value;
}
}
//move up the tree if not already at the top
if ($this->parentNode->uid != $this->ownerDocument->uid) {
$this->parentNode->_getNamespaceDeclarationsInScope($nsMap);
}
return $nsMap;
} //_getNamespacesInScope
/**
* Returns the default xmlns declaration for the current element
* @return string The default xmlns declaration for the current element
*/
function getDefaultNamespaceDeclaration() {
if (in_array('xmlns', $this->namespaceURIMap)) {
foreach ($this->namespaceURIMap as $key => $value) {
if ($value == 'xmlns') {
return $key;
}
}
}
else if ($this->parentNode->uid != $this->ownerDocument->uid) {
return $this->parentNode->getDefaultNamespaceDeclaration();
}
else {
return '';
}
} //getDefaultNamespaceDeclaration
/**
* Copies all namespace declarations in scope to the namespace URI map of the current element
*/
function copyNamespaceDeclarationsLocally() {
$nsMap = $this->getNamespaceDeclarationsInScope();
//add xmlns declarations as attributes
foreach ($nsMap as $key => $value) {
if ($value == 'xmlns') {
$this->declareDefaultNamespace($key);
}
else {
$this->declareNamespace($value, $key);
}
}
} //copyNamespaceDeclarationsLocally
/**
* Adds elements with the specified tag name to a NodeList collection
* @param Object The NodeList collection
* @param string The namespaceURI of matching elements
* @param string The localName of matching elements
*/
function getNamedElementsNS(&$nodeList, $namespaceURI, $localName) {
if ((($namespaceURI == $this->namespaceURI) || ($namespaceURI == '*')) &&
(($localName == $this->localName) || ($localName == '*'))) {
$nodeList->appendNode($this);
}
$total = $this->childCount;
for ($i = 0; $i < $total; $i++) {
if ($this->childNodes[$i]->nodeType == DOMIT_ELEMENT_NODE) {
$this->childNodes[$i]->getNamedElementsNS($nodeList, $namespaceURI, $localName);
}
}
} //getNamedElementsNS
/**
* Returns the concatented text of the current node and its children
* @return string The concatented text of the current node and its children
*/
function getText() {
$text = '';
$numChildren = $this->childCount;
for ($i = 0; $i < $numChildren; $i++) {
$child =& $this->childNodes[$i];
$text .= $child->getText();
}
return $text;
} //getText
/**
* If a child text node exists, sets the nodeValue to $data. A child text node is created if none exists
* @param string The text data of the node
*/
function setText($data) {
switch ($this->childCount) {
case 1:
if ($this->firstChild->nodeType == DOMIT_TEXT_NODE) {
$this->firstChild->setText($data);
}
break;
case 0:
$childTextNode =& $this->ownerDocument->createTextNode($data);
$this->appendChild($childTextNode);
break;
default:
//do nothing. Maybe throw error???
}
} //setText
/**
* Retrieves a NodeList of child elements with the specified tag name
* @param string The matching element tag name
* @return Object A NodeList of found elements
*/
function &getElementsByTagName($tagName) {
$nodeList = new DOMIT_NodeList();
$this->getNamedElements($nodeList, $tagName);
return $nodeList;
} //getElementsByTagName
/**
* Retrieves a NodeList of child elements with the specified namespaceURI and localName
* @param string The namespaceURI
* @param string The localName
* @return Object A NodeList of found elements
*/
function &getElementsByTagNameNS($namespaceURI, $localName) {
$nodeList = new DOMIT_NodeList();
$this->getNamedElementsNS($nodeList, $namespaceURI, $localName);
return $nodeList;
} //getElementsByTagNameNS
/**
* Returns the attribute node whose ID is given by elementId.
* @param string The id of the matching element
* @param boolean True if XML spec is to be strictly adhered to (only attributes xml:id are considered valid)
* @return Object The found attribute or null
*/
function &_getElementByID($elementID, $isStrict) {
if ($isStrict) {
$myAttrNode =& $this->getAttributeNodeNS(DOMIT_XML_NAMESPACE, 'id');
if (($myAttrNode != null)&& ($myAttrNode->getValue() == $elementID)) return $myAttrNode;
}
else {
$myAttrNode =& $this->getAttributeNodeNS('', 'ID');
if (($myAttrNode != null)&& ($myAttrNode->getValue() == $elementID)) return $myAttrNode;
$myAttrNode =& $this->getAttributeNodeNS('', 'id');
if (($myAttrNode != null)&& ($myAttrNode->getValue() == $elementID)) return $myAttrNode;
}
$total = $this->childCount;
for ($i = 0; $i < $total; $i++) {
if ($this->childNodes[$i]->nodeType == DOMIT_ELEMENT_NODE) {
$foundNode =& $this->childNodes[$i]->_getElementByID($elementID, $isStrict);
if ($foundNode != null) {
return $foundNode;
}
}
}
$null = null;
return $null;
} //_getElementByID
/**
* Retrieves an element or DOMIT_NodeList of elements corresponding to an Xpath-like expression.
* @param string The query pattern
* @param int If a single node is to be returned (rather than the entire NodeList) the index of that node
* @return mixed A NodeList or single node that matches the pattern
*/
function &getElementsByPath($pattern, $nodeIndex = 0) {
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_getelementsbypath.php');
$gebp = new DOMIT_GetElementsByPath();
$myResponse =& $gebp->parsePattern($this, $pattern, $nodeIndex);
return $myResponse;
} //getElementsByPath
/**
* Retrieves an element or DOMIT_NodeList of elements corresponding to an Xpath-like attribute expression (NOT YET IMPLEMENTED!)
* @param string The query pattern
* @param int If a single node is to be returned (rather than the entire NodeList) the index of that node
* @return mixed A NodeList or single node that matches the pattern
*/
function &getElementsByAttributePath($pattern, $nodeIndex = 0) {
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_getelementsbypath.php');
$gabp = new DOMIT_GetElementsByAttributePath();
$myResponse =& $gabp->parsePattern($this, $pattern, $nodeIndex);
return $myResponse;
} //getElementsByAttributePath
/**
* Adds all child nodes of the specified nodeType to the NodeList
* @param Object The NodeList collection
* @param string The nodeType of matching nodes
*/
function getTypedNodes(&$nodeList, $type) {
$numChildren = $this->childCount;
for ($i = 0; $i < $numChildren; $i++) {
$child =& $this->childNodes[$i];
if ($child->nodeType == $type) {
$nodeList->appendNode($child);
}
if ($child->hasChildNodes()) {
$child->getTypedNodes($nodeList, $type);
}
}
} //getTypedNodes
/**
* Adds all child nodes of the specified nodeValue to the NodeList
* @param Object The NodeList collection
* @param string The nodeValue of matching nodes
*/
function getValuedNodes(&$nodeList, $value) {
$numChildren = $this->childCount;
for ($i = 0; $i < $numChildren; $i++) {
$child =& $this->childNodes[$i];
if ($child->nodeValue == $value) {
$nodeList->appendNode($child);
}
if ($child->hasChildNodes()) {
$child->getValuedNodes($nodeList, $value);
}
}
} //getValuedNodes
/**
* Gets the value of the specified attribute, if it exists
* @param string The attribute name
* @return string The attribute value
*/
function getAttribute($name) {
$returnNode =& $this->attributes->getNamedItem($name);
if ($returnNode == null) {
return '';
}
else {
return $returnNode->getValue();
}
} //getAttribute
/**
* Gets the value of the attribute with the specified namespaceURI and localName, if it exists
* @param string The namespaceURI
* @param string The localName
* @return string The attribute value
*/
function getAttributeNS($namespaceURI, $localName) {
$returnNode =& $this->attributes->getNamedItemNS($namespaceURI, $localName);
if ($returnNode == null) {
return '';
}
else {
return $returnNode->getValue();
}
} //getAttributeNS
/**
* Sets the value of the specified attribute; creates a new attribute if one doesn't exist
* @param string The attribute name
* @param string The desired attribute value
*/
function setAttribute($name, $value) {
$returnNode =& $this->attributes->getNamedItem($name);
if ($returnNode == null) {
$newAttr = new DOMIT_Attr($name);
$newAttr->setValue($value);
$this->attributes->setNamedItem($newAttr);
}
else {
$returnNode->setValue($value);
}
} //setAttribute
/**
* Sets the value of the specified attribute; creates a new attribute if one doesn't exist
* @param string The attribute namespaceURI
* @param string The attribute qualifiedName
* @param string The desired attribute value
*/
function setAttributeNS($namespaceURI, $qualifiedName, $value) {
//get localName
$colonIndex = strpos($qualifiedName, ":");
if ($colonIndex !== false) {
$localName = substr($qualifiedName, ($colonIndex + 1));
}
else {
$localName = $qualifiedName;
}
$returnNode =& $this->attributes->getNamedItemNS($namespaceURI, $localName);
if ($returnNode == null) {
//create this manually in case element has no ownerDocument to reference
$newAttr = new DOMIT_Attr($qualifiedName);
$newAttr->prefix = substr($qualifiedName, 0, $colonIndex);
$newAttr->localName = $localName;
$newAttr->namespaceURI = $namespaceURI;
$newAttr->setValue($value);
$this->attributes->setNamedItemNS($newAttr);
$newAttr->ownerElement =& $this;
}
else {
$returnNode->setValue($value);
}
} //setAttributeNS
/**
* Removes the specified attribute
* @param string The name of the attribute to be removed
*/
function removeAttribute($name) {
$returnNode =& $this->attributes->removeNamedItem($name);
} //removeAttribute
/**
* Removes the specified attribute
* @param string The namespaceURI of the attribute to be removed
* @param string The localName of the attribute to be removed
*/
function removeAttributeNS($namespaceURI, $localName) {
$returnNode =& $this->attributes->removeNamedItemNS($namespaceURI, $localName);
unset($returnNode->ownerElement);
$returnNode->ownerElement = null;
} //removeAttributeNS
/**
* Determines whether an attribute with the specified name exists
* @param string The name of the attribute
* @return boolean True if the attribute exists
*/
function hasAttribute($name) {
$returnNode =& $this->attributes->getNamedItem($name);
return ($returnNode != null);
} //hasAttribute
/**
* Determines whether an attribute with the specified namespaceURI and localName exists
* @param string The namespaceURI of the attribute
* @param string The localName of the attribute
* @return boolean True if the attribute exists
*/
function hasAttributeNS($namespaceURI, $localName) {
$returnNode =& $this->attributes->getNamedItemNS($namespaceURI, $localName);
return ($returnNode != null);
} //hasAttributeNS
/**
* Determines whether the element has any atributes
* @return boolean True if the element has any atributes
*/
function hasAttributes() {
return ($this->attributes->getLength() > 0);
} //hasChildNodes
/**
* Gets a reference to the specified attribute node
* @param string The attribute name
* @return Object A reference to the found node, or null
*/
function &getAttributeNode($name) {
$returnNode =& $this->attributes->getNamedItem($name);
return $returnNode;
} //getAttributeNode
/**
* Gets a reference to the specified attribute node
* @param string The attribute namespaceURI
* @param string The attribute localName
* @return Object A reference to the found node, or null
*/
function &getAttributeNodeNS($namespaceURI, $localName) {
$returnNode =& $this->attributes->getNamedItemNS($namespaceURI, $localName);
return $returnNode;
} //getAttributeNodeNS
/**
* Adds an attribute node to the current element
* @param Object The attribute node to be added
* @return Object A reference to the newly added node
*/
function &setAttributeNode(&$newAttr) {
$returnNode =& $this->attributes->setNamedItem($newAttr);
return $returnNode;
} //setAttributeNode
/**
* Adds an attribute node to the current element (namespace aware)
* @param Object The attribute node to be added
* @return Object A reference to the newly added node
*/
function &setAttributeNodeNS(&$newAttr) {
$returnNode =& $this->attributes->setNamedItemNS($newAttr);
$newAttr->ownerElement =& $this;
return $returnNode;
} //setAttributeNodeNS
/**
* Removes an attribute node from the current element
* @param Object The attribute node to be removed
* @return Object A reference to the removed node
*/
function &removeAttributeNode(&$oldAttr) {
$attrName = $oldAttr->getName();
$returnNode =& $this->attributes->removeNamedItem($attrName);
if ($returnNode == null) {
DOMIT_DOMException::raiseException(DOMIT_NOT_FOUND_ERR,
'Target attribute not found.');
}
else {
return $returnNode;
}
} //removeAttributeNode
/**
* Collapses adjacent text nodes in entire element subtree
*/
function normalize() {
if ($this->hasChildNodes()) {
$currNode =& $this->childNodes[0];
while ($currNode->nextSibling != null) {
$nextNode =& $currNode->nextSibling;
if (($currNode->nodeType == DOMIT_TEXT_NODE) &&
($nextNode->nodeType == DOMIT_TEXT_NODE)) {
$currNode->nodeValue .= $nextNode->nodeValue;
$this->removeChild($nextNode);
}
else {
$currNode->normalize();
}
if ($currNode->nextSibling != null) {
$currNode =& $currNode->nextSibling;
}
}
}
} //normalize
/**
* Generates an array representation of the node and its children
* @return Array A representation of the node and its children
*/
function toArray() {
$arReturn = array($this->nodeName => array("attributes" => $this->attributes->toArray()));
$total = $this->childCount;
for ($i = 0; $i < $total; $i++) {
$arReturn[$this->nodeName][$i] = $this->childNodes[$i]->toArray();
}
return $arReturn;
} //toArray
/**
* Copies a node and/or its children
* @param boolean True if all child nodes are also to be cloned
* @return Object A copy of the node and/or its children
*/
function &cloneNode($deep = false) {
$className = get_class($this);
$clone = new $className($this->nodeName);
$clone->attributes =& $this->attributes->createClone($deep);
if ($this->namespaceURI) {
$clone->namespaceURI = $this->namespaceURI;
$clone->localName = $this->localName;
}
if ($deep) {
$total = $this->childCount;
for ($i = 0; $i < $total; $i++) {
$currentChild =& $this->childNodes[$i];
$clone->appendChild($currentChild->cloneNode($deep));
}
}
return $clone;
} //cloneNode
/**
* Generates a string representation of the node and its children
* @param boolean True if HTML readable output is desired
* @param boolean True if illegal xml characters in text nodes and attributes should be converted to entities
* @return string The string representation
*/
function toString($htmlSafe = false, $subEntities = false) {
$result = '<' . $this->nodeName;
$result .= $this->attributes->toString(false, $subEntities);
if ($this->ownerDocument->isNamespaceAware) {
foreach ($this->namespaceURIMap as $key => $value) {
$result .= ' xmlns:' . $value . '="' . $key . '"';
}
}
//get children
$myNodes =& $this->childNodes;
$total = count($myNodes);
if ($total != 0) {
$result .= '>';
for ($i = 0; $i < $total; $i++) {
$child =& $myNodes[$i];
$result .= $child->toString(false, $subEntities);
}
$result .= '</' . $this->nodeName . '>';
}
else {
if ($this->ownerDocument->doExpandEmptyElementTags) {
if (in_array($this->nodeName, $this->ownerDocument->expandEmptyElementExceptions)) {
$result .= ' />';
}
else {
$result .= '></' . $this->nodeName . '>';
}
}
else {
if (in_array($this->nodeName, $this->ownerDocument->expandEmptyElementExceptions)) {
$result .= '></' . $this->nodeName . '>';
}
else {
$result .= ' />';
}
}
}
if ($htmlSafe) $result = $this->forHTML($result);
return $result;
} //toString
} //DOMIT_Element
/**
* A parent class for Text and CDATA Section nodes
*
* @package domit-xmlparser
* @subpackage domit-xmlparser-main
* @author John Heinstein <johnkarl@nbnet.nb.ca>
*/
class DOMIT_CharacterData extends DOMIT_Node {
/**
* Prevents direct instantiation of DOMIT_CharacterData class
* @abstract
*/
function DOMIT_CharacterData() {
DOMIT_DOMException::raiseException(DOMIT_ABSTRACT_CLASS_INSTANTIATION_ERR,
'Cannot instantiate abstract class DOMIT_CharacterData');
} //DOMIT_CharacterData
/**
* Gets the node value of the current text node
* @return string The node value of the current text node
*/
function getData() {
return $this->nodeValue;
} //getData
/**
* Sets the text contained in the current node to $data.
* @param string The text data of the node
*/
function setData($data) {
$this->nodeValue = $data;
} //setData
/**
* Gets the length of the text in the current node
* @return int The length of the text in the current node
*/
function getLength() {
return strlen($this->nodeValue);
} //getLength
/**
* Gets a subset of the current node text
* @param int The starting point of the substring
* @param int The length of the substring
* @return string The subset of the current node text
*/
function substringData($offset, $count) {
$totalChars = $this->getLength();
if (($offset < 0) || (($offset + $count) > $totalChars)) {
DOMIT_DOMException::raiseException(DOMIT_INDEX_SIZE_ERR,
'Character Data index out of bounds.');
}
else {
$data = $this->getData();
return substr($data, $offset, $count);
}
} //substringData
/**
* Appends the specified text to the current node text
* @param string The text to be appended
*/
function appendData($arg) {
$this->setData($this->getData() . $arg);
} //appendData
/**
* Inserts text at the sepecified offset
* @param int The insertion point
* @param string The text to be inserted
*/
function insertData($offset, $arg) {
$totalChars = $this->getLength();
if (($offset < 0) || ($offset > $totalChars)) {
DOMIT_DOMException::raiseException(DOMIT_INDEX_SIZE_ERR,
'Character Data index out of bounds.');
}
else {
$data = $this->getData();
$pre = substr($data, 0, $offset);
$post = substr($data, $offset);
$this->setData(($pre . $arg . $post));
}
} //insertData
/**
* Deletes a subset of the current node text
* @param int The starting point of the deletion
* @param int The length of the deletion
*/
function deleteData($offset, $count) {
$totalChars = $this->getLength();
if (($offset < 0) || (($offset + $count) > $totalChars)) {
DOMIT_DOMException::raiseException(DOMIT_INDEX_SIZE_ERR,
'Character Data index out of bounds.');
}
else {
$data = $this->getData();
$pre = substr($data, 0, $offset);
$post = substr($data, ($offset + $count));
$this->setData(($pre . $post));
}
} //substringData
/**
* Replaces a subset of the current node text with the specified text
* @param int The starting point of the replacement
* @param int The length of the replacement
* @param string The replacement text
*/
function replaceData($offset, $count, $arg) {
$totalChars = $this->getLength();
if (($offset < 0) || (($offset + $count) > $totalChars)) {
DOMIT_DOMException::raiseException(DOMIT_INDEX_SIZE_ERR,
'Character Data index out of bounds.');
}
else {
$data = $this->getData();
$pre = substr($data, 0, $offset);
$post = substr($data, ($offset + $count));
$this->setData(($pre . $arg . $post));
}
} //replaceData
} //DOMIT_CharacterData
/**
* A class representing the DOM Text Node
*
* @package domit-xmlparser
* @subpackage domit-xmlparser-main
* @author John Heinstein <johnkarl@nbnet.nb.ca>
*/
class DOMIT_TextNode extends DOMIT_CharacterData {
/**
* DOM Text Node constructor
* @param string The text of the node
*/
function DOMIT_TextNode($data) {
$this->_constructor();
$this->nodeType = DOMIT_TEXT_NODE;
$this->nodeName = '#text';
$this->setText($data);
} //DOMIT_TextNode
/**
* Returns the text contained in the current node
* @return string The text of the current node
*/
function getText() {
return $this->nodeValue;
} //getText
/**
* Sets the text contained in the current node to $data.
* @param string The text data of the node
*/
function setText($data) {
$this->nodeValue = $data;
} //setText
/**
* Splits a single node into multiple nodes, based on the specified offset
* @param int The offset point for the split
* @return Object The newly created text node
*/
function &splitText($offset) {
$totalChars = $this->getLength();
if (($offset < 0) || ($offset > $totalChars)) {
DOMIT_DOMException::raiseException(DOMIT_INDEX_SIZE_ERR,
'Character Data index out of bounds.');
}
else {
$data = $this->getData();
$pre = substr($data, 0, $offset);
$post = substr($data, $offset);
$this->setText($pre);
//create new text node
$className = get_class($this);
$newTextNode = new $className($post);
$newTextNode->ownerDocument =& $this->ownerDocument;
if ($this->parentNode->lastChild->uid == $this->uid) {
$this->parentNode->appendChild($newTextNode);
}
else {
$this->parentNode->insertBefore($newTextNode, $this);
}
return $newTextNode;
}
} //splitText
/**
* Generates an array representation of the node and its children
* @return Array A representation of the node and its children
*/
function toArray() {
return $this->toString();
} //toArray
/**
* Copies a node and/or its children
* @param boolean True if all child nodes are also to be cloned
* @return Object A copy of the node and/or its children
*/
function &cloneNode($deep = false) {
$className = get_class($this);
$clone = new $className($this->nodeValue);
return $clone;
} //cloneNode
/**
* Generates a string representation of the node and its children
* @param boolean True if HTML readable output is desired
* @param boolean True if illegal xml characters should be converted to entities
* @return string The string representation
*/
function toString($htmlSafe = false, $subEntities = false) {
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php');
global $DOMIT_defined_entities_flip;
$result = $subEntities ? DOMIT_Utilities::convertEntities($this->nodeValue,
$DOMIT_defined_entities_flip) : $this->nodeValue;
if ($htmlSafe) $result = $this->forHTML($result);
return $result;
} //toString
} //DOMIT_TextNode
/**
* A class representing the DOM CDATA Section
*
* @package domit-xmlparser
* @subpackage domit-xmlparser-main
* @author John Heinstein <johnkarl@nbnet.nb.ca>
*/
class DOMIT_CDATASection extends DOMIT_TextNode {
/**
* DOM CDATA Section node constructor
* @param string The text of the node
*/
function DOMIT_CDATASection($data) {
$this->_constructor();
$this->nodeType = DOMIT_CDATA_SECTION_NODE;
$this->nodeName = '#cdata-section';
$this->setText($data);
} //DOMIT_CDATASection
/**
* Generates a string representation of the node and its children
* @param boolean True if HTML readable output is desired
* @param boolean True if illegal xml characters should be converted to entities
* @return string The string representation
*/
function toString($htmlSafe = false, $subEntities = false) {
$result = '<![CDATA[';
$result .= $subEntities ? str_replace("]]>", "]]>", $this->nodeValue) :
$this->nodeValue;
$result .= ']]>';
if ($htmlSafe) $result = $this->forHTML($result);
return $result;
} //toString
} //DOMIT_CDATASection
/**
* A class representing the Attr node
*
* @package domit-xmlparser
* @subpackage domit-xmlparser-main
* @author John Heinstein <johnkarl@nbnet.nb.ca>
*/
class DOMIT_Attr extends DOMIT_Node {
/** @var boolean True if the attribute has been modified since parsing (NOT YET IMPLEMENTED!) */
var $specified = false;
/** @var Object A reference to the element to which the attribute is assigned */
var $ownerElement = null;
/**
* DOM Attr node constructor
* @param string The name of the attribute
*/
function DOMIT_Attr($name) {
$this->_constructor();
$this->nodeType = DOMIT_ATTRIBUTE_NODE;
$this->nodeName =$name;
} //DOMIT_Attr
/**
* Returns the name of the attribute
* @return string The name of the attribute
*/
function getName() {
return $this->nodeName;
} //getName
/**
* Indicates whether an attribute has been modified since parsing
* @return boolean True if the node has been modified
*/
function getSpecified() {
return $this->specified;
} //getSpecified
/**
* Returns the value of the attribute
* @return string The value of the attribute
*/
function getValue() {
return $this->nodeValue;
} //getValue
/**
* Sets the value of the attribute
* @param string The value of the attribute
*/
function setValue($value) {
$this->nodeValue = $value;
} //setValue
/**
* Returns the text contained in the current node
* @return string The text of the current node
*/
function getText() {
return $this->nodeValue;
} //getText
/**
* Sets the text contained in the current node to $data.
* @param string The text data of the node
*/
function setText($data) {
$this->nodeValue = $data;
} //setText
/**
* Copies a node and/or its children
* @param boolean True if all child nodes are also to be cloned
* @return Object A copy of the node and/or its children
*/
function &cloneNode($deep = false) {
$className = get_class($this);
$clone = new $className($this->nodeName);
$clone->nodeValue = $this->nodeValue;
if ($this->namespaceURI) {
$clone->namespaceURI = $this->namespaceURI;
$clone->localName = $this->localName;
}
return $clone;
} //cloneNode
/**
* Generates a string representation of the node and its children
* @param boolean True if HTML readable output is desired
* @param boolean True if HTML entities should be substituted
* @return string The string representation
*/
function toString($htmlSafe = false, $subEntities = false) {
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php');
global $DOMIT_defined_entities_flip;
$result = ' ' . $this->nodeName . '="';
$result .= $subEntities ? DOMIT_Utilities::convertEntities($this->nodeValue,
$DOMIT_defined_entities_flip) : $this->nodeValue;
$result .= '"';
if ($htmlSafe) $result = $this->forHTML($result);
return $result;
} //toString
} //DOMIT_Attr
/**
* A class representing the DOM Document Fragment node
*
* @package domit-xmlparser
* @subpackage domit-xmlparser-main
* @author John Heinstein <johnkarl@nbnet.nb.ca>
*/
class DOMIT_DocumentFragment extends DOMIT_ChildNodes_Interface {
/**
* DOM Document Fragment node constructor
*/
function DOMIT_DocumentFragment() {
$this->_constructor();
$this->nodeType = DOMIT_DOCUMENT_FRAGMENT_NODE;
$this->nodeName ='#document-fragment';
$this->nodeValue = null;
$this->childNodes = array();
} //DOMIT_DocumentFragment
/**
* Generates an array representation of the node and its children
* @return Array A representation of the node and its children
*/
function toArray() {
$arReturn = array();
$total = $this->childCount;
for ($i = 0; $i < $total; $i++) {
$arReturn[$i] = $this->childNodes[$i]->toArray();
}
return $arReturn;
} //toArray
/**
* Copies a node and/or its children
* @param boolean True if all child nodes are also to be cloned
* @return Object A copy of the node and/or its children
*/
function &cloneNode($deep = false) {
$className = get_class($this);
$clone = new $className();
if ($deep) {
$total = $this->childCount;
for ($i = 0; $i < $total; $i++) {
$currentChild =& $this->childNodes[$i];
$clone->appendChild($currentChild->cloneNode($deep));
}
}
return $clone;
} //cloneNode
/**
* Generates a string representation of the node and its children
* @param boolean True if HTML readable output is desired
* @return string The string representation
*/
function toString($htmlSafe = false, $subEntities = false) {
//get children
$result = '';
$myNodes =& $this->childNodes;
$total = count($myNodes);
if ($total != 0) {
for ($i = 0; $i < $total; $i++) {
$child =& $myNodes[$i];
$result .= $child->toString(false, $subEntities);
}
}
if ($htmlSafe) $result = $this->forHTML($result);
return $result;
} //toString
} //DOMIT_DocumentFragment
/**
* A class representing the DOM Comment node
*
* @package domit-xmlparser
* @subpackage domit-xmlparser-main
* @author John Heinstein <johnkarl@nbnet.nb.ca>
*/
class DOMIT_Comment extends DOMIT_CharacterData {
/**
* DOM Comment node constructor
* @param string The
*/
function DOMIT_Comment($nodeValue) {
$this->_constructor();
$this->nodeType = DOMIT_COMMENT_NODE;
$this->nodeName = '#comment';
$this->nodeValue = $nodeValue;
} //DOMIT_Comment
/**
* Returns the text contained in the current node
* @return string The text of the current node
*/
function getText() {
return $this->nodeValue;
} //getText
/**
* Sets the text contained in the current node to $data.
* @param string The text data of the node
*/
function setText($data) {
$this->nodeValue = $data;
} //setText
/**
* Generates an array representation of the node and its children
* @return Array A representation of the node and its children
*/
function toArray() {
return $this->toString();
} //toArray
/**
* Copies a node and/or its children
* @param boolean True if all child nodes are also to be cloned
* @return Object A copy of the node and/or its children
*/
function &cloneNode($deep = false) {
$className = get_class($this);
$clone = new $className($this->nodeValue);
return $clone;
} //cloneNode
/**
* Generates a string representation of the node and its children
* @param boolean True if HTML readable output is desired
* @return string The string representation
*/
function toString($htmlSafe = false) {
$result = '<!--' . $this->nodeValue . '-->';
if ($htmlSafe) $result = $this->forHTML($result);
return $result;
} //toString
} //DOMIT_Comment
/**
* A class representing the DOM Processing Instruction node
*
* @package domit-xmlparser
* @subpackage domit-xmlparser-main
* @author John Heinstein <johnkarl@nbnet.nb.ca>
*/
class DOMIT_ProcessingInstruction extends DOMIT_Node {
/**
* DOM Processing Instruction node constructor
* @param string The
*/
function DOMIT_ProcessingInstruction($target, $data) {
$this->_constructor();
$this->nodeType = DOMIT_PROCESSING_INSTRUCTION_NODE;
$this->nodeName = $target;
$this->nodeValue = $data;
} //DOMIT_ProcessingInstruction
/**
* Returns the processing instruction target
* @return string The processing instruction target
*/
function getTarget() {
return $this->nodeName;
} //getTarget
/**
* Returns the processing instruction data
* @return string The processing instruction data
*/
function getData() {
return $this->nodeValue;
} //getData
/**
* Returns the text contained in the current node
* @return string The text of the current node
*/
function getText() {
return ($this->nodeName . ' ' . $this->nodeValue);
} //getText
/**
* Generates an array representation of the node and its children
* @return Array A representation of the node and its children
*/
function toArray() {
return $this->toString();
} //toArray
/**
* Copies a node and/or its children
* @param boolean True if all child nodes are also to be cloned
* @return Object A copy of the node and/or its children
*/
function &cloneNode($deep = false) {
$className = get_class($this);
$clone = new $className($this->nodeName, $this->nodeValue);
return $clone;
} //cloneNode
/**
* Generates a string representation of the node and its children
* @param boolean True if HTML readable output is desired
* @return string The string representation
*/
function toString($htmlSafe = false) {
$result = '<' . '?' . $this->nodeName . ' ' . $this->nodeValue . '?' . '>';
if ($htmlSafe) $result = $this->forHTML($result);
return $result;
} //toString
} //DOMIT_ProcessingInstruction
/**
* A class representing the DOM Document Type node
*
* @package domit-xmlparser
* @subpackage domit-xmlparser-main
* @author John Heinstein <johnkarl@nbnet.nb.ca>
*/
class DOMIT_DocumentType extends DOMIT_Node {
/** @var string The doctype name */
var $name;
/** @var Object True if the entity has been modified since parsing (NOT YET IMPLEMENTED!) */
var $entities;
/** @var Object A NodeList of notation nodes (NOT YET IMPLEMENTED!) */
var $notations;
/** @var Object A NodeList of elements (NOT YET IMPLEMENTED!) */
var $elements;
/** @var string The full text of the doctype */
var $text;
/** @var string The public identifier of the external subset */
var $publicID;
/** @var string The system identifier of the external subset */
var $systemID;
/** @var string The full text of internal subset */
var $internalSubset;
/**
* DOM Document Type node constructor
* @param string The
*/
function DOMIT_DocumentType($name, $text) {
$this->_constructor();
$this->nodeType = DOMIT_DOCUMENT_TYPE_NODE;
$this->nodeName = $name;
$this->name = $name;
$this->entities = null; //implement later
$this->notations = null; //implement later
$this->elements = null; //implement later
$this->text = $text;
} //DOMIT_DocumentType
/**
* Returns the text contained in the current node
* @return string The text of the current node
*/
function getText() {
return $this->text;
} //getText
/**
* Returns the name of the doctype node
* @return string The name of the doctype node
*/
function getName() {
return $this->name;
} //getName
/**
* Generates an array representation of the node and its children
* @return Array A representation of the node and its children
*/
function toArray() {
return $this->toString();
} //toArray
/**
* Copies a node and/or its children
* @param boolean True if all child nodes are also to be cloned
* @return Object A copy of the node and/or its children
*/
function &cloneNode($deep = false) {
$className = get_class($this);
$clone = new $className($this->nodeName, $this->text);
return $clone;
} //cloneNode
/**
* Generates a string representation of the node and its children
* @param boolean True if HTML readable output is desired
* @return string The string representation
*/
function toString($htmlSafe = false) {
$result = $this->text;
if ($htmlSafe) $result = $this->forHTML($result);
return $result;
} //toString
} //DOMIT_DocumentType
/**
* A class representing the DOM Notation node (NOT YET IMPLEMENTED!)
*
* @package domit-xmlparser
* @subpackage domit-xmlparser-main
* @author John Heinstein <johnkarl@nbnet.nb.ca>
*/
class DOMIT_Notation extends DOMIT_Node {
/**
* DOM Notation node constructor (NOT YET IMPLEMENTED!)
*/
function DOMIT_Notation() {
DOMIT_DOMException::raiseException(DOMIT_NOT_SUPPORTED_ERR,
'Cannot instantiate DOMIT_Notation class. Notation nodes not yet supported.');
} //DOMIT_Notation
} //DOMIT_Notation
/**
* Manages the generation of a DOMIT! document from SAX events
*
* @package domit-xmlparser
* @subpackage domit-xmlparser-main
* @author John Heinstein <johnkarl@nbnet.nb.ca>
*/
class DOMIT_Parser {
/** @var Object A reference to the resulting xmldoc */
var $xmlDoc = null;
/** @var Object A reference to the current node in the parsing process */
var $currentNode = null;
/** @var Object A reference to the last child in the parsing process */
var $lastChild = null;
/** @var boolean True if currently parsing a CDATA Section */
var $inCDATASection = false; //flag for Expat
/** @var boolean True if currently parsing a Text node */
var $inTextNode = false;
/** @var boolean True is CDATA Section nodes are not to be converted into Text nodes */
var $preserveCDATA;
/** @var string A container for holding the currently parsed text data */
var $parseContainer = '';
/** @var string The current docutype text */
var $parseItem = '';
/** @var boolean True if waiting for an element to which to apply namespace declaration(s) */
var $waitingForElementToDeclareNamespaces = false;
/** @var boolean True if waiting for an element to which to apply namespace declaration(s) */
var $tempNamespaceURIMap = array();
/**
* Parses xml text using Expat
* @param Object A reference to the DOM document that the xml is to be parsed into
* @param string The text to be parsed
* @param boolean True if CDATA Section nodes are not to be converted into Text nodes
* @return boolean True if the parsing is successful
*/
function parse (&$myXMLDoc, $xmlText, $preserveCDATA = true) {
$this->xmlDoc =& $myXMLDoc;
$this->lastChild =& $this->xmlDoc;
$this->preserveCDATA = $preserveCDATA;
//create instance of expat parser (should be included in php distro)
if (version_compare(phpversion(), '5.0', '<=')) {
if ($this->xmlDoc->isNamespaceAware) {
$parser = xml_parser_create_ns('');
}
else {
$parser = xml_parser_create('');
}
}
else {
if ($this->xmlDoc->isNamespaceAware) {
$parser = xml_parser_create_ns();
}
else {
$parser = xml_parser_create();
}
}
//set handlers for SAX events
xml_set_object($parser, $this);
xml_set_character_data_handler($parser, 'dataElement');
xml_set_default_handler($parser, 'defaultDataElement');
xml_set_notation_decl_handler($parser, 'notationElement');
xml_set_processing_instruction_handler($parser, 'processingInstructionElement');
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
if (!$this->xmlDoc->preserveWhitespace) {
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
}
else {
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);
}
if ($this->xmlDoc->isNamespaceAware) {
xml_set_start_namespace_decl_handler($parser, 'startNamespaceDeclaration');
xml_set_end_namespace_decl_handler($parser, 'endNamespaceDeclaration');
xml_set_element_handler($parser, 'startElementNS', 'endElement');
$this->xmlDoc->namespaceURIMap[DOMIT_XML_NAMESPACE] = 'xml';
}
else {
xml_set_element_handler($parser, 'startElement', 'endElement');
}
//parse out whitespace - (XML_OPTION_SKIP_WHITE = 1 does not
//seem to work consistently across versions of PHP and Expat
if (!$this->xmlDoc->preserveWhitespace) {
$xmlText = eregi_replace('>' . "[[:space:]]+" . '<' , '><', $xmlText);
}
$success = xml_parse($parser, $xmlText);
$this->xmlDoc->errorCode = xml_get_error_code($parser);
$this->xmlDoc->errorString = xml_error_string($this->xmlDoc->errorCode);
xml_parser_free($parser);
return $success;
} //parse
/**
* Parses xml text using SAXY
* @param Object A reference to the DOM document that the xml is to be parsed into
* @param string The text to be parsed
* @param boolean True if CDATA Section nodes are not to be converted into Text nodes
* @return boolean True if the parsing is successful
*/
function parseSAXY(&$myXMLDoc, $xmlText, $preserveCDATA = true, $definedEntities) {
require_once(DOMIT_INCLUDE_PATH . 'xml_saxy_parser.php');
$this->xmlDoc =& $myXMLDoc;
$this->lastChild =& $this->xmlDoc;
//create instance of SAXY parser
$parser = new SAXY_Parser();
$parser->appendEntityTranslationTable($definedEntities);
//not yet implemented in SAXY!!!
$parser->preserveWhitespace = $this->xmlDoc->preserveWhitespace;
if ($this->xmlDoc->isNamespaceAware) {
$parser->setNamespaceAwareness(true);
$parser->xml_set_start_namespace_decl_handler(array(&$this, 'startNamespaceDeclaration'));
$parser->xml_set_end_namespace_decl_handler(array(&$this, 'endNamespaceDeclaration'));
$parser->xml_set_element_handler(array(&$this, 'startElementNS'), array(&$this, 'endElement'));
$this->xmlDoc->namespaceURIMap[DOMIT_XML_NAMESPACE] = 'xml';
}
else {
$parser->xml_set_element_handler(array(&$this, 'startElement'), array(&$this, 'endElement'));
}
$parser->xml_set_character_data_handler(array(&$this, 'dataElement'));
$parser->xml_set_doctype_handler(array(&$this, 'doctypeElement'));
$parser->xml_set_comment_handler(array(&$this, 'commentElement'));
$parser->xml_set_processing_instruction_handler(array(&$this, 'processingInstructionElement'));
if ($preserveCDATA) {
$parser->xml_set_cdata_section_handler(array(&$this, 'cdataElement'));
}
$success = $parser->parse($xmlText);
$this->xmlDoc->errorCode = $parser->xml_get_error_code();
$this->xmlDoc->errorString = $parser->xml_error_string($this->xmlDoc->errorCode);
return $success;
} //parseSAXY
/**
* Generates and appends a new text node from the parseContainer text
*/
function dumpTextNode() {
$currentNode =& $this->xmlDoc->createTextNode($this->parseContainer);
$this->lastChild->appendChild($currentNode);
$this->inTextNode = false;
$this->parseContainer = '';
} //dumpTextNode
/**
* Catches a start element event and processes the data
* @param Object A reference to the current SAX parser
* @param string The tag name of the current element
* @param Array An array of the element attributes
*/
function startElement(&$parser, $name, $attrs) {
if ($this->inTextNode) {
$this->dumpTextNode();
}
$currentNode =& $this->xmlDoc->createElement($name);
$this->lastChild->appendChild($currentNode);
reset ($attrs);
while (list($key, $value) = each ($attrs)) {
$currentNode->setAttribute($key, $value);
}
$this->lastChild =& $currentNode;
} //startElement
/**
* Catches a start element event and processes the data
* @param Object A reference to the current SAX parser
* @param string The tag name of the current element
* @param Array An array of the element attributes
*/
function startElementNS(&$parser, $name, $attrs) {
if ($this->inTextNode) {
$this->dumpTextNode();
}
$colonIndex = strrpos($name, ":");
if ($colonIndex !== false) {
//force to lower case because Expat for some reason forces to upper case
$namespaceURI = strtolower(substr($name, 0, $colonIndex));
$prefix = $this->xmlDoc->namespaceURIMap[$namespaceURI];
if ($prefix != '') {
$qualifiedName = $prefix . ":" . substr($name, ($colonIndex + 1));
}
else {
$qualifiedName = substr($name, ($colonIndex + 1));
}
}
else {
$namespaceURI = '';
$qualifiedName = $name;
}
$currentNode =& $this->xmlDoc->createElementNS($namespaceURI, $qualifiedName);
$this->lastChild->appendChild($currentNode);
//add attributes
reset ($attrs);
while (list($key, $value) = each ($attrs)) {
$colonIndex = strrpos($key, ":");
if ($colonIndex !== false) {
//force to lower case because Expat for some reason forces to upper case
$namespaceURI = strtolower(substr($key, 0, $colonIndex));
$qualifiedName = $this->xmlDoc->namespaceURIMap[$namespaceURI] .
":" . substr($key, ($colonIndex + 1));;
}
else {
//if containing element has a namespace, technically
//attribute namespace should be added here, but we'll do it elsewhere
//so toNormalizedString outputs the same things as is input
$namespaceURI = '';
$qualifiedName = $key;
}
$currentNode->setAttributeNS($namespaceURI, $qualifiedName, $value);
}
//and add xmlns attributes
if ($this->waitingForElementToDeclareNamespaces) {
//map namespace declarations to element
foreach ($this->tempNamespaceURIMap as $key => $value) {
$currentNode->namespaceURIMap[$key] = $value ;
//xmlns prefix has prefix: http://www.w3.org/2000/xmlns/
$currentNode->setAttributeNS(DOMIT_XMLNS_NAMESPACE, ('xmlns:' . $value), $key);
}
//reset variables
$this->tempNamespaceURIMap = array();
$this->waitingForElementToDeclareNamespaces = false;
}
$this->lastChild =& $currentNode;
} //startElementNS
/**
* Catches an end element event and processes the data
* @param Object A reference to the current SAX parser
* @param string The tag name of the current element
*/
function endElement(&$parser, $name) {
if ($this->inTextNode) {
$this->dumpTextNode();
}
$this->lastChild =& $this->lastChild->parentNode;
} //endElement
/**
* Catches a data event and processes the text
* @param Object A reference to the current SAX parser
* @param string The current text data
*/
function dataElement(&$parser, $data) {
if (!$this->inCDATASection) {
$this->inTextNode = true;
}
$this->parseContainer .= $data;
} //dataElement
/**
* Catches a CDATA Section event and processes the text
* @param Object A reference to the current SAX parser
* @param string The current text data
*/
function cdataElement(&$parser, $data) {
$currentNode =& $this->xmlDoc->createCDATASection($data);
$this->lastChild->appendChild($currentNode);
} //cdataElement
/**
* Catches a default data event and processes the data
* @param Object A reference to the current SAX parser
* @param string The current data
*/
function defaultDataElement(&$parser, $data) {
if ((strlen($data) > 2) && ($this->parseItem == '')){
$pre = strtoupper(substr($data, 0, 3));
switch ($pre) {
case '<?X': //xml declaration
$this->processingInstructionElement($parser, 'xml', substr($data, 6, (strlen($data) - 6 - 2)));
break;
case '<!E': //dtd entity
$this->xmlDoc->doctype .= "\n " . $data;
break;
case '<![': //cdata section coming
if ($this->preserveCDATA) {
$this->inCDATASection = true;
}
break;
case '<!-': //comment
$currentNode = $this->commentElement($this, substr($data, 4, (strlen($data) - 7)));
break;
case '<!D': //doctype
$this->parseItem = 'doctype';
$this->parseContainer = $data;
break;
case ']]>': //cdata end tag
if ($this->preserveCDATA) {
$currentNode =& $this->xmlDoc->createCDATASection($this->parseContainer);
$this->lastChild->appendChild($currentNode);
$this->inCDATASection = false;
$this->parseContainer = '';
}
else {
$this->dumpTextNode();
}
break;
}
}
else {
switch ($this->parseItem) {
case 'doctype':
$this->parseContainer .= $data;
if ($data == '>') {
$this->doctypeElement($parser, $this->parseContainer);
$this->parseContainer = '';
$this->parseItem = '';
}
else if ($data == '[') {
$this->parseItem = 'doctype_inline';
}
break;
case 'doctype_inline':
$this->parseContainer .= $data;
if ($data == ']') {
$this->parseItem = 'doctype';
}
else if ($data{(strlen($data) - 1)} == '>') {
$this->parseContainer .= "\n ";
}
break;
}
}
} //defaultDataElement
/**
* Catches a doctype event and processes the data
* @param Object A reference to the current SAX parser
* @param string The current data
*/
function doctypeElement(&$parser, $data) {
$start = strpos($data, '<!DOCTYPE');
$name = trim(substr($data, $start));
$end = strpos($name, ' ');
$name = substr($name, 0, $end);
$currentNode = new DOMIT_DocumentType($name, $data);
$currentNode->ownerDocument =& $this->xmlDoc;
$this->lastChild->appendChild($currentNode);
$this->xmlDoc->doctype =& $currentNode;
} //doctypeElement
/**
* Catches a notation node event and processes the data
* @param Object A reference to the current SAX parser
* @param string The current notation data
*/
function notationElement(&$parser, $data) {
//add to doctype string
if (($this->parseItem == 'doctype_inline') || ($this->parseItem == 'doctype')) {
$this->parseContainer .= $data;
}
} //notationElement
/**
* Catches a comment node event and processes the data
* @param Object A reference to the current SAX parser
* @param string The comment data
*/
function commentElement(&$parser, $data) {
if ($this->inTextNode) {
$this->dumpTextNode();
}
$currentNode =& $this->xmlDoc->createComment($data);
$this->lastChild->appendChild($currentNode);
} //commentElement
/**
* Catches a processing instruction node event and processes the data
* @param Object A reference to the current SAX parser
* @param string The target of the processing instruction data
* @param string The processing instruction data
*/
function processingInstructionElement(&$parser, $target, $data) {
if ($this->inTextNode) {
$this->dumpTextNode();
}
$currentNode =& $this->xmlDoc->createProcessingInstruction($target, $data);
$this->lastChild->appendChild($currentNode);
if (strtolower($target) == 'xml') {
$this->xmlDoc->xmlDeclaration =& $currentNode;
}
} //processingInstructionElement
/**
* Catches a start namespace declaration event and processes the data
* @param Object A reference to the current SAX parser
* @param string The namespace prefix
* @param string The namespace uri
*/
function startNamespaceDeclaration(&$parser, $prefix, $uri) {
//make uri lower case because Expat forces it to upper case for some reason
$this->xmlDoc->namespaceURIMap[strtolower($uri)] = $prefix;
//set up a switch so when the target element arrives, namespaces can be mapped to it
$this->waitingForElementToDeclareNamespaces = true;
$this->tempNamespaceURIMap[strtolower($uri)] = $prefix;
} //startNamespaceDeclaration
/**
* Catches an end namespace declaration event
* @param Object A reference to the current SAX parser
* @param string The namespace prefix
*/
function endNamespaceDeclaration(&$parser, $prefix) {
//do nothing; could remove from map, but would hardly be optimal
} //endNamespaceDeclaration
} //DOMIT_Parser
?>
|