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
|
# Features covered: domDoc and docObj command
#
# This file contains a collection of tests for the two interfaces to
# DOM docs, the token interface (the domDoc command) and the tcl
# command interface ([$docObj method ...]).
#
# domDoc-1.*: asXML, asHTML
# domDoc-2.*: publicId, systemId
# domDoc-3.*: toXSLTcmd
# domDoc-4.*: asText
# domDoc-5.*: normalize
# domDoc-6.*: nodetype
# domDoc-7.*: insertBefore
# domDoc-8.*: insertBeforeFromScript
# domDoc-9.*: replaceChild
# domDoc-10.*: getElementById
# domDoc-11.*: firstChild
# domDoc-12.*: lastChild
# domDoc-13.*: appendChild
# domDoc-14.*: removeChild
# domDoc-15.*: hasChildNodes
# domDoc-16.*: childNodes
# domDoc-17.*: ownerDocument
# domDoc-18.*: appendFromList
# domDoc-19.*: appendXML
# domDoc-20.*: selectNodes
# domDoc-21.*: baseURI
# domDoc-22.*: appendFromScript
# domDoc-23.*: getElementsByTagNameNS
# domDoc-24.*: cdataSectionElements
# domDoc-25.*: selectNodesNamespaces
# domDoc-26.*: fragments list
# domDoc-27.*: deleteXPathCache
# domDoc-28.*: createElementNS
#
# Copyright (c) 2004 - 2007 Rolf Ade.
source [file join [file dir [info script]] loadtdom.tcl]
test domDoc-1.1 {asXML -escapeNonASCII} {
set doc [dom parse [tdom::xmlReadFile \
[file join [file dir [info script]] data/i18n_1.xml]]]
set result [$doc asXML -escapeNonASCII]
$doc delete
set result
} {<test>абвгдежзий</test>
}
test domDoc-1.2 {asXML -escapeNonASCII; comments and PI's are not altered} {
set doc [dom parse [tdom::xmlReadFile \
[file join [file dir [info script]] data/i18n_2.xml]]]
set result [$doc asXML -indent none -escapeNonASCII]
$doc delete
set result
} "<root withUmlauts=\"äöüß\"><!-- A comment with german umlauts: \u00E4\u00F6\u00FC\u00DF --><?\u00E4\u00F6\u00FC\u00DF A processing node with german umlauts?>
german umlauts: äöüß
</root>"
test domDoc-1.3 {asHTML -escapeNonASCII -htmlEntities} {
set doc [dom parse {<html><body>äü„‟†</body></html>}]
set result [$doc asHTML -escapeNonASCII -htmlEntities]
$doc delete
set result
} {<html><body>äü„‟†</body></html>}
set doc [dom parse <root/>]
test domDoc-1.4 {asXML -doctypeDeclaration} {
$doc asXML -doctypeDeclaration 1
} {<!DOCTYPE root>
<root/>
}
test domDoc-1.5 {asXML -doctypeDeclaration without boolean value (error)} {
set errMsg ""
catch {$doc asXML -doctypeDeclaration} errMsg
set errMsg
} {-doctypeDeclaration must have a boolean value as argument}
test domDoc-1.6 {asXML -doctypeDeclaration 0} {
$doc asXML -doctypeDeclaration 0
} {<root/>
}
$doc delete
test domDoc-1.7 {asXML -doctypeDeclaration} {
set doc [dom parse {<!DOCTYPE root PUBLIC "-//foo//DTD bar x.y//EN"
"file:///boo.baz"><root/>}]
set result [$doc asXML -doctypeDeclaration 1]
$doc delete
set result
} {<!DOCTYPE root PUBLIC "-//foo//DTD bar x.y//EN" "file:///boo.baz">
<root/>
}
test domDoc-1.8 {asXML -doctypeDeclaration} {
set doc [dom parse {<!DOCTYPE root SYSTEM "file:///boo.baz"><root/>}]
set result [$doc asXML -doctypeDeclaration 1]
$doc delete
set result
} {<!DOCTYPE root SYSTEM "file:///boo.baz">
<root/>
}
test domDoc-1.9 {asXML -doctypeDeclaration} {
set doc [dom parse {<!DOCTYPE root SYSTEM "file:///boo.baz"><root/>}]
set result [$doc asXML -doctypeDeclaration true]
$doc delete
set result
} {<!DOCTYPE root SYSTEM "file:///boo.baz">
<root/>
}
test domDoc-1.10 {asXML - unknown option} {
set doc [dom parse {<!DOCTYPE root SYSTEM "file:///boo.baz"><root/>}]
set errMsg ""
catch {$doc asXML -fooOption 1} errMsg
$doc delete
set errMsg
} {bad option "-fooOption": must be -indent, -channel, -escapeNonASCII, -doctypeDeclaration, -xmlDeclaration, -encString, -escapeAllQuot, -indentAttrs, -nogtescape, or -noEmptyElementTag}
test domDoc-1.11 {asXML - non boolean value to -doctypeDeclaration} {
set doc [dom parse {<!DOCTYPE root SYSTEM "file:///boo.baz"><root/>}]
set errMsg ""
catch {$doc asXML -doctypeDeclaration foo} errMsg
$doc delete
set errMsg
} {expected boolean value but got "foo"}
test domDoc-1.12 {asXML - shortened option} {
set doc [dom parse {<!DOCTYPE root SYSTEM "file:///boo.baz"><root/>}]
set result [$doc asXML -doctype 1]
$doc delete
set result
} {<!DOCTYPE root SYSTEM "file:///boo.baz">
<root/>
}
test domDoc-1.13 {asHTML -doctypeDeclaration} {
set doc [dom createDocument HTML]
set result [$doc asHTML -doctypeDeclaration 1]
$doc delete
set result
} {<!DOCTYPE HTML>
<html></html>}
test domDoc-1.14 {asHTML -doctypeDeclaration} {
set doc [dom parse {<!DOCTYPE HTML
PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>boo</p></body></html>}]
set result [$doc asHTML -doctypeDeclaration 1]
$doc delete
set result
} {<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>boo</p></body></html>}
test domDoc-1.15 {asXML - processing-instruction without pi value} {
set doc [dom parse {<doc><?p?></doc>}]
set result [$doc asXML -indent none]
$doc delete
set result
} {<doc><?p ?></doc>}
test domDoc-1.16 {asXML - processing-instruction without pi value} {
set doc [dom parse {<doc><?p ?></doc>}]
set result [$doc asXML -indent none]
$doc delete
set result
} {<doc><?p ?></doc>}
test domDoc-1.17 {asHTML - content of script/style tags} {
set doc [dom parse {
<html><script>a & b</script><style>foo < bar</style></html>
}]
set result [$doc asHTML]
$doc delete
set result
} {<html>
<script>a & b</script><style>foo < bar</style>
</html>}
test domDoc-1.18 {asXML -escapeAllQuot} {
set doc [dom parse {<doc>This is "strange"</doc>}]
set result [$doc asXML -escapeAllQuot]
$doc delete
set result
} {<doc>This is "strange"</doc>
}
test domDoc-1.19 {asXML -escapeAllQuot} {
set doc [dom parse {<doc>This is "strange"</doc>}]
set result [$doc asXML]
$doc delete
set result
} {<doc>This is "strange"</doc>
}
test domDoc-1.20 {asXML - indentation of comments} {
set doc [dom parse {<doc>
<!--Comment 1-->
<e1/>
<!--Comment 2--></doc>}]
set result [$doc asXML -indent 4]
$doc delete
set result
} {<doc>
<!--Comment 1-->
<e1/>
<!--Comment 2-->
</doc>
}
test domDoc-1.21 {asXML -indentAttrs} {
set doc [dom parse {<Element attr1="val1" attr2="val2"/>}]
set result [$doc asXML -indentAttrs 4]
$doc delete
set result
} {<Element
attr1="val1"
attr2="val2"/>
}
test domDoc-1.22 {asXML} {
set doc [dom createDocument doc]
set result [$doc asXML]
$doc delete
set result
} {<doc/>
}
test domDoc-1.23 {asXML -xmlDeclaration} {
set doc [dom createDocument doc]
set result [$doc asXML -xmlDeclaration 1]
$doc delete
set result
} {<?xml version="1.0"?>
<doc/>
}
test domDoc-1.23 {asXML -xmlDeclaration} {
set doc [dom createDocument doc]
set result [$doc asXML -xmlDeclaration 1]
$doc delete
set result
} {<?xml version="1.0"?>
<doc/>
}
test domDoc-1.24 {asXML just -encString without -xmlDeclaration} {
set doc [dom createDocument doc]
set result [$doc asXML -encString foo]
$doc delete
set result
} {<doc/>
}
test domDoc-1.25 {asXML -xmlDeclaration -encString} {
set doc [dom createDocument doc]
set result [$doc asXML -xmlDeclaration 1 -encString foo]
$doc delete
set result
} {<?xml version="1.0" encoding="foo"?>
<doc/>
}
test domDoc-1.26 {asXML -xmlDeclaration, encoding set by encoding method} {
set doc [dom createDocument doc]
$doc encoding "foo"
set result [$doc asXML -xmlDeclaration 1]
$doc delete
set result
} {<?xml version="1.0" encoding="foo"?>
<doc/>
}
test domDoc-1.27 {asXML -xmlDeclaration -encString} {
set doc [dom createDocument doc]
set result [catch {
[$doc asXML -xmlDeclaration 1 -encString foo \
-encString bar -wrongOption]
}]
$doc delete
set result
} 1
test domDoc-1.28 {asXML -xmlDeclaration not xml compliant -encString} {
set doc [dom createDocument doc]
set result [$doc asXML -xmlDeclaration 1 -encString 1\u2345]
$doc delete
set result
} [subst -nocommands -novariables {<?xml version="1.0" encoding="1\u2345"?>
<doc/>
}]
test domDoc-1.29 {asXML -nogtescape} {
set doc [dom parse {<doc attr="foo>bar">></doc>}]
set result [$doc asXML -nogtescape -indent none]
$doc delete
set result
} {<doc attr="foo>bar">></doc>}
test domDoc-1.30 {asXML -noEmptyElementTag} {
set doc [dom parse {<doc><elm/></doc>}]
set result [$doc asXML -noEmptyElementTag -indent none]
$doc delete
set result
} {<doc><elm></elm></doc>}
test domDoc-1.31 {asXML '"' in attribute value} {
# emacs: "
set doc [dom createDocument doc]
set root [$doc documentElement]
$root setAttribute attr "foo\"bar"
set result [$doc asXML -indent none]
$doc delete
set result
} {<doc attr="foo"bar"/>}
test domDoc-1.32 {asXML -indent tabs} {
set doc [dom parse {<doc><a><b/></a></doc>}]
set result [$doc asXML -indent tabs]
$doc delete
set result
} "<doc>\n\t<a>\n\t\t<b/>\n\t</a>\n</doc>\n"
test domDoc-1.33 {asXML -indent tabs} {
set doc [dom parse {<doc><a><b/></a><c><d><f/></d></c><g/></doc>}]
set result [$doc asXML -indent tabs]
$doc delete
set result
} "<doc>\n\t<a>\n\t\t<b/>\n\t</a>\n\t<c>\n\t\t<d>\n\t\t\t<f/>\n\t\t</d>\n\t</c>\n\t<g/>\n</doc>\n"
test domDoc-1.34 {asXML -indent tabs -noEmptyElementTag} {
set doc [dom parse {<doc><a><b/></a><c><d><f/></d></c><g/></doc>}]
set result [$doc asXML -indent tabs -noEmptyElementTag]
$doc delete
set result
} "<doc>\n\t<a>\n\t\t<b></b>\n\t</a>\n\t<c>\n\t\t<d>\n\t\t\t<f></f>\n\t\t</d>\n\t</c>\n\t<g></g>\n</doc>\n"
test domDoc-1.35 {asXML -indent tabs -indentAttrs tabs} {
set doc [dom parse {<doc><a a1="a1" a2="a2"><b/></a><c><d a1="a1" a2="a2"><f/></d></c><g/></doc>}]
set result [$doc asXML -indent tabs -indentAttrs tabs]
$doc delete
set result
} "<doc>\n\t<a\n\t\ta1=\"a1\"\n\t\ta2=\"a2\">\n\t\t<b/>\n\t</a>\n\t<c>\n\t\t<d\n\t\t\ta1=\"a1\"\n\t\t\ta2=\"a2\">\n\t\t\t<f/>\n\t\t</d>\n\t</c>\n\t<g/>\n</doc>\n"
test domDoc-1.36 {asXML -indent tabs -indentAttrs <num>} {
set doc [dom parse {<doc><a a1="a1" a2="a2"><b/></a><c><d a1="a1" a2="a2"><f/></d></c><g/></doc>}]
set result [$doc asXML -indent tabs -indentAttrs 2]
$doc delete
set result
} "<doc>\n\t<a\n\t a1=\"a1\"\n\t a2=\"a2\">\n\t\t<b/>\n\t</a>\n\t<c>\n\t\t<d\n\t\t a1=\"a1\"\n\t\t a2=\"a2\">\n\t\t\t<f/>\n\t\t</d>\n\t</c>\n\t<g/>\n</doc>\n"
test domDoc-1.37 {asHTML -onlyContents} {
set doc [dom parse {<html><body><p>boo</p></body></html>}]
set result [[$doc documentElement] asHTML -onlyContents]
$doc delete
set result
} {<body><p>boo</p></body>}
test domDoc-1.38 {asHTML -breakLines} {
set doc [dom parse {<html><body><p>boo</p></body></html>}]
set result [$doc asHTML -breakLines]
$doc delete
set result
} {<html
><body
><p
>boo</p></body></html>}
set doc [dom parse <root/>]
test domDoc-2.1 {publicId - no publicId there} {
$doc publicId
} {}
test domDoc-2.2 {systemId - no systemId there} {
$doc systemId
} {}
$doc delete
set doc [dom parse {<!DOCTYPE root PUBLIC "-//foo//DTD bar x.y//EN" "file:///boo.baz"><root/>}]
test domDoc-2.3 {publicId from parsed document} {
$doc publicId
} {-//foo//DTD bar x.y//EN}
test domDoc-2.4 {systemId from parsed document} {
$doc systemId
} {file:///boo.baz}
$doc delete
set doc [dom parse {<!DOCTYPE root SYSTEM "file:///boo.baz"><root/>}]
test domDoc-2.5 {publicId but document has only SYSTEM} {
$doc publicId
} {}
test domDoc-2.6 {systemId, document has only SYSTEM} {
$doc systemId
} {file:///boo.baz}
test domDoc-2.7 {publicId - set public identifier} {
set result [$doc publicId "file:///woo.hoo"]
append result " [$doc publicId]"
} { file:///woo.hoo}
test domDoc-2.8 {publicId - set public identifier} {
$doc publicId "http://www.tdom.org"
$doc asXML -indent no -doctypeDeclaration 1
} {<!DOCTYPE root PUBLIC "http://www.tdom.org" "file:///boo.baz">
<root/>}
test domDoc-2.9 {systemId - set system identifier} {
set result [$doc systemId "file:///woo.hoo"]
append result " [$doc systemId]"
} {file:///boo.baz file:///woo.hoo}
test domDoc-2.10 {systemId - set system identifier} {
$doc systemId "file:///whooze.moo"
$doc asXML -indent no -doctypeDeclaration 1
} {<!DOCTYPE root PUBLIC "http://www.tdom.org" "file:///whooze.moo">
<root/>}
test domDoc-2.11 {publicId - set to empty string} {
$doc publicId ""
$doc asXML -indent no -doctypeDeclaration 1
} {<!DOCTYPE root SYSTEM "file:///whooze.moo">
<root/>}
test domDoc-2.12 {systemId - set to empty string} {
$doc systemId ""
$doc asXML -indent no -doctypeDeclaration 1
} {<!DOCTYPE root>
<root/>}
$doc delete
set doc [dom parse <root/>]
set xslt1 {
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:param name="param1" select="'param1Default'"/>
<xsl:param name="param2" select="'param2Default'"/>
<xsl:param name="param3" select="'param3Default'"/>
<xsl:template match="/">
<xsl:value-of select="$param1"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$param2"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$param3"/>
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>}
test domDoc-3.1 {toXSLTcmd} {
set xslt [dom parse -keepEmpties $xslt1]
set xsltCmd [$xslt toXSLTcmd]
$xsltCmd -parameters {param2 newValue param3 "this Value"} $doc resultDoc
set result [$resultDoc asXML -indent none]
$resultDoc delete
$xsltCmd -parameters {param1 "that Value"} $doc resultDoc
append result [$resultDoc asXML -indent none]
$resultDoc delete
$xsltCmd -parameters {param3 "another" param1 "and this"} $doc resultDoc
append result [$resultDoc asXML -indent none]
$resultDoc delete
rename $xsltCmd {}
set result
} {param1Default newValue this Value that Value param2Default param3Default and this param2Default another }
set xslt2 {
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:text>dummy result</xsl:text>
<xsl:message>This is from xsl:message</xsl:message>
</xsl:template>
</xsl:stylesheet>}
proc msgCmd1 {msg terminate} {
global result
append result "msgCmd1: $msg "
}
proc msgCmd2 {msg terminate} {
global result
append result "msgCmd2: $msg"
}
test domDoc-3.2 {toXSLTcmd} {
set xslt [dom parse -keepEmpties $xslt2]
set xsltCmd [$xslt toXSLTcmd]
set result ""
$xsltCmd -xsltmessagecmd msgCmd1 $doc resultDoc
$resultDoc delete
$xsltCmd -xsltmessagecmd msgCmd2 $doc resultDoc
$resultDoc delete
rename $xsltCmd {}
set result
} {msgCmd1: This is from xsl:message msgCmd2: This is from xsl:message}
test domDoc-3.3 {toXSLTcmd} {
set xslt [dom parse -keepEmpties $xslt1]
set xsltCmd [$xslt toXSLTcmd]
set result [catch {$xsltCmd -bogusOption foo $doc resultDoc} errMsg]
lappend result $errMsg
lappend result [catch {$xsltCmd $doc resultDoc}]
lappend result [$resultDoc asXML -indent none]
$resultDoc delete
rename $xsltCmd {}
set result
} {1 {bad option "-bogusOption": must be -parameters, -ignoreUndeclaredParameters, -maxApplyDepth, or -xsltmessagecmd} 0 {param1Default param2Default param3Default }}
test domDoc-3.4 {toXSLTcmd} {
set xslt [dom parse -keepEmpties $xslt1]
set xsltCmd [$xslt toXSLTcmd]
set result [catch {$xsltCmd -xsltmessagecmd msgCmd1} errMsg]
rename $xsltCmd {}
lappend result $errMsg
} {1 {wrong # args: should be "?-parameters parameterList? ?-ignoreUndeclaredParameters? ?-maxApplyDepth int? ?-xsltmessagecmd cmd? <xmlDocObj> ?objVar?"}}
test domDoc-3.5 {toXSLTcmd} {
set xslt [dom parse -keepEmpties $xslt1]
set xsltCmd [$xslt toXSLTcmd]
set result [catch {$xsltCmd $doc resultDoc bogus} errMsg]
rename $xsltCmd {}
lappend result $errMsg
} {1 {wrong # args: should be "?-parameters parameterList? ?-ignoreUndeclaredParameters? ?-maxApplyDepth int? ?-xsltmessagecmd cmd? <xmlDocObj> ?objVar?"}}
test domDoc-3.6 {toXSLTcmd} {
set xslt [dom parse -keepEmpties $xslt1]
set xsltCmd [$xslt toXSLTcmd]
set result [catch {$xsltCmd -parameters {param1 foo} -parameters {param2 foo} $doc resultDoc} errMsg]
rename $xsltCmd {}
lappend result $errMsg
} {1 {only one -parameters option allowed}}
test domDoc-3.7 {toXSLTcmd} {
set xslt [dom parse -keepEmpties $xslt1]
set xsltCmd [$xslt toXSLTcmd]
set result [catch {$xsltCmd}]
$xsltCmd delete
set result
} {1}
test domDoc-3.8 {toXSLTcmd} {
set xslt [dom parse -keepEmpties $xslt1]
set xsltCmd [$xslt toXSLTcmd]
set result [catch {$xsltCmd delete bogus}]
$xsltCmd delete
set result
} {1}
test domDoc-3.9 {toXSLTcmd} {
set xslt [dom parse -keepEmpties $xslt1]
set xsltCmd [$xslt toXSLTcmd]
set result [catch {$xsltCmd transform} errMsg]
$xsltCmd delete
set result
} {1}
test domDoc-3.10 {toXSLTcmd} {
set xslt [dom parse -keepEmpties $xslt1]
set xsltCmd [$xslt toXSLTcmd]
$xsltCmd transform $doc resultDoc
set result [$resultDoc asXML -indent none]
$resultDoc delete
$xsltCmd delete
set result
} {param1Default param2Default param3Default }
set xslt3 {<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output cdata-section-elements="foo
doc b bar"/>
<xsl:template match="/">
<doc>mixed element <b>this is</b> more text</doc>
</xsl:template>
</xsl:stylesheet>}
test domDoc-3.11 {toXSLTcmd} {
set xslt [dom parse -keepEmpties $xslt3]
set xsltCmd [$xslt toXSLTcmd]
set result [list]
for {set x 0} {$x < 2} {incr x} {
$xsltCmd $doc resultDoc
lappend result [lsort [$resultDoc cdataSectionElements *]]
lappend result [$resultDoc asXML -indent none]
$resultDoc delete
}
$xsltCmd delete
set result
} {{b bar doc foo} {<doc><![CDATA[mixed element ]]><b><![CDATA[this is]]></b><![CDATA[ more text]]></doc>} {b bar doc foo} {<doc><![CDATA[mixed element ]]><b><![CDATA[this is]]></b><![CDATA[ more text]]></doc>}}
$doc delete
test domDoc-4.1 {asText - syntax check} {
dom parse <root/> doc
set result [catch {$doc asText foo}]
$doc delete
set result
} {1}
test domDoc-4.2 {asText} {
dom parse {<root>pcdata <child>foo bar grill</child></root>} doc
set result [$doc asText]
$doc delete
set result
} {pcdata foo bar grill}
test domDoc-4.3 {asText} {
dom parse {<root>pcdata <![CDATA[<greeting>Hello, world!</greeting>]]>
more pcdata</root>} doc
set result [$doc asText]
$doc delete
set result
} {pcdata <greeting>Hello, world!</greeting>
more pcdata}
test domDoc-4.4 {asText} {
dom parse {<root>pcdata</root>} doc
$doc documentElement root
set newCDATAnode \
[$doc createCDATASection "<greeting>Hello, world!</greeting>"]
$root appendChild $newCDATAnode
set result [$doc asText]
$doc delete
set result
} {pcdata}
test domDoc-4.5 {asText} {
dom parse {<root>encoded chars: > < & " '</root>} doc
set result [$doc asText]
$doc delete
set result
} {encoded chars: > < & " '}
# emacs: "
test domDoc-5.1 {normalize} {
set doc [dom parse <root><child>text</child></root>]
$doc documentElement root
set cdataNode [$doc createCDATASection "cdata section text"]
set child [$root firstChild]
$child appendChild $cdataNode
$doc normalize
set result [llength [$child childNodes]]
lappend result [[$child firstChild] data]
$doc delete
set result
} {2 text}
test domDoc-5.2 {normalize} {
set doc [dom parse <root><child>text</child></root>]
$doc documentElement root
set cdataNode [$doc createCDATASection "cdata section text"]
set child [$root firstChild]
$child appendChild $cdataNode
$doc normalize -forXPath
set result [llength [$child childNodes]]
lappend result [[$child firstChild] data]
$doc delete
set result
} {1 {textcdata section text}}
test domDoc-5.3 {normalize} {
set doc [dom parse <root><child/></root>]
$doc documentElement root
set cdataNode [$doc createCDATASection "cdata section text"]
set textNode [$doc createTextNode text]
set child [$root firstChild]
$child appendChild $cdataNode
$child appendChild $textNode
set result [llength [$child childNodes]]
$doc normalize -forXPath
lappend result [llength [$child childNodes]]
lappend result [[$child firstChild] data]
$doc delete
set result
} {2 1 {cdata section texttext}}
test domDoc-5.4 {normalize} {
set doc [dom parse <root><child/></root>]
$doc documentElement root
set cdataNode [$doc createCDATASection "cdata section text"]
set child [$root firstChild]
$child appendChild $cdataNode
$doc normalize
set result [$cdataNode nodeType]
$doc normalize -forXPath
lappend result [$cdataNode nodeType]
$doc delete
set result
} {CDATA_SECTION_NODE TEXT_NODE}
test domDoc-5.5 {normalize} {
set doc [dom parse <root><child/></root>]
$doc documentElement root
set textNode [$doc createTextNode ""]
set child [$root firstChild]
$child appendChild $textNode
set result [llength [$child childNodes]]
$doc normalize
lappend result [llength [$child childNodes]]
$doc delete
set result
} {1 0}
test domDoc-5.6 {normalize} {
set doc [dom parse <root><child/></root>]
$doc documentElement root
set cdataNode [$doc createCDATASection ""]
set child [$root firstChild]
$child appendChild $cdataNode
$doc normalize
set result [llength [$child childNodes]]
$doc normalize -forXPath
lappend result [llength [$child childNodes]]
$doc delete
set result
} {1 0}
test domDoc-6.1 {nodeType} {
set doc [dom parse <root/>]
set result [$doc nodeType]
$doc delete
set result
} {DOCUMENT_NODE}
test domDoc-6.2 {nodeType} {
set doc [dom parse <root/>]
set result [catch {$doc nodeType foo}]
$doc delete
set result
} {1}
test domDoc-7.1 {insertBefore} {
set doc [dom parse {<!-- Comment --><root/>}]
set root [$doc documentElement]
set newPI [$doc createProcessingInstruction myPI pivalue]
$doc insertBefore $newPI $root
set result [$doc asXML -indent none]
$doc delete
set result
} {<!-- Comment --><?myPI pivalue?><root/>}
test domDoc-7.2 {insertBefore} {
set doc [dom parse {<!-- Comment --><root/>}]
set newPI [$doc createProcessingInstruction myPI pivalue]
$doc insertBefore $newPI ""
set result [$doc asXML -indent none]
$doc delete
set result
} {<!-- Comment --><root/><?myPI pivalue?>}
test domDoc-7.3 {insertBefore} {
set doc [dom parse {<!-- Comment --><root><child/></root>}]
set newPI [$doc createProcessingInstruction myPI pivalue]
set root [$doc documentElement]
set child [$root firstChild]
set result [catch {$doc insertBefore $newPI $child} errMsg]
lappend result $errMsg
$doc delete
set result
} {1 NOT_FOUND_ERR}
namespace eval nodeCmds {
dom createNodeCmd elementNode e1
dom createNodeCmd elementNode e2
dom createNodeCmd commentNode c
dom createNodeCmd textNode t
dom createNodeCmd cdataNode cdata
dom createNodeCmd piNode pi
dom createNodeCmd parserNode parser
}
test domDoc-8.1 {insertBeforeFromScript} {
set doc [dom parse {<root><child/></root>}]
$doc documentElement root
$doc insertBeforeFromScript {
nodeCmds::e1
} $root
set result [$doc asXML -indent none]
$doc delete
set result
} {<e1/><root><child/></root>}
test domDoc-8.2 {insertBeforeFromScript} {
set doc [dom parse {<root><child/></root>}]
$doc insertBeforeFromScript {
nodeCmds::e1
} ""
set result [$doc asXML -indent none]
$doc delete
set result
} {<root><child/></root><e1/>}
test domDoc-8.3 {insertBeforeFromScript} {
set doc [dom parse {<root><child/></root>}]
$doc documentElement root
set result [catch {$root insertBeforeFromScript {
nodeCmds::e1
nodeCmds::e1 {
# This is intentionally wrong
set foo 1 + 1
}
} $root}]
lappend result [$doc asXML -indent none]
$doc delete
set result
} {1 <root><child/></root>}
test domDoc-9.1 {replaceChild} {
set doc [dom parse {<!-- Comment --><root><child/></root>}]
set root [$doc documentElement]
set newNode [$doc createElement newNode]
$doc replaceChild $newNode $root
set result [$doc asXML -indent none]
lappend result [[$doc documentElement] nodeName]
$doc delete
set result
} {<!-- Comment --><newNode/> newNode}
set getElementByIdSetup {
set doc [dom parse {
<!DOCTYPE root [
<!ELEMENT root (elem*)>
<!ELEMENT elem ANY>
<!ATTLIST elem
id ID #IMPLIED
name CDATA #IMPLIED>
]>
<root>
<elem id="7" name="this"/>
<elem id="4a" name="that"/>
<elem name="and"/>
<elem id="a2" name="this"/>
</root>}]
}
test domDoc-10.1 {getElementById} -setup $getElementByIdSetup -body {
set result [[$doc getElementById "4a"] @name]
lappend result [$doc getElementById "dontexists"]
} -cleanup {
$doc delete
} -result {that {}}
test domDoc-10.2 {getElementById - only IDs at parsing time will be found} \
-setup $getElementByIdSetup -body {
set root [$doc documentElement]
set elemNode [$root selectNodes {elem[3]}]
if {[$elemNode hasAttribute id]} {
error "error in the test code"
}
$elemNode setAttribute id "new"
$doc getElementById "new"
} -cleanup {
$doc delete
} -result {}
test domDoc-10.3 {getElementById} -setup $getElementByIdSetup -body {
set root [$doc documentElement]
set elemNode [$root selectNodes {elem[2]}]
if {![$elemNode hasAttribute id]} {
error "error in the test code"
}
$elemNode setAttribute id "new"
[$doc getElementById "new"] getAttribute name
} -cleanup {
$doc delete
} -result that
test domDoc-10.4 {getElementById} -setup $getElementByIdSetup -body {
set root [$doc documentElement]
set elemNode [$root selectNodes {elem[2]}]
if {![$elemNode hasAttribute id]} {
error "error in the test code"
}
$root removeChild $elemNode
[$doc getElementById "4a"] getAttribute name
} -cleanup {
$doc delete
} -result that
test domDoc-10.5 {getElementById} -setup $getElementByIdSetup -body {
set root [$doc documentElement]
set elemNode [$root selectNodes {elem[2]}]
if {![$elemNode hasAttribute id]} {
error "error in the test code"
}
$elemNode removeAttribute id
$doc getElementById "4a"
} -cleanup {
$doc delete
} -result {}
test domDoc-11.1 {firstChild} {
set doc [dom createDocumentNode]
set result [$doc firstChild]
$doc delete
set result
} {}
test domDoc-11.2 {firstChild} {
set doc [dom parse <root/>]
set result [[$doc firstChild] nodeName]
$doc delete
set result
} {root}
test domDoc-11.3 {firstChild} {
set doc [dom parse {<?beforeRoot this?><root/><?afterRoot that?>}]
set result [[$doc firstChild] nodeName]
$doc delete
set result
} {beforeRoot}
test domDoc-11.4 {firstChild} {
set doc [dom parse {<root/>}]
set node [$doc firstChild]
set newNode [$doc createElement newNode]
$doc insertBefore $newNode $node
set result [[$doc firstChild] nodeName]
$doc delete
set result
} {newNode}
test domDoc-11.5 {Delete top level node} {
set doc [dom parse {<!---comment on top level--><root/>}]
[$doc firstChild] delete
set result [$doc asXML -indent none]
$doc delete
set result
} {<root/>}
test domDoc-11.6 {Delete top level node} {
set doc [dom parse {<!---comment on top level--><root/>}]
[$doc documentElement] delete
set result [$doc asXML -indent none]
$doc delete
set result
} {<!---comment on top level-->}
test domDoc-12.1 {lastChild} {
set doc [dom createDocumentNode]
set result [$doc lastChild]
$doc delete
set result
} {}
test domDoc-12.2 {lastChild} {
set doc [dom parse <root/>]
set result [[$doc lastChild] nodeName]
$doc delete
set result
} {root}
test domDoc-12.3 {lastChild} {
set doc [dom parse {<?beforeRoot this?><root/><?afterRoot that?>}]
set result [[$doc lastChild] nodeName]
$doc delete
set result
} {afterRoot}
test domDoc-12.4 {lastChild} {
set doc [dom parse {<root/>}]
set newNode [$doc createElement newNode]
$doc appendChild $newNode
set result [[$doc lastChild] nodeName]
lappend result [[$doc lastChild] parentNode]
$doc delete
set result
} {newNode {}}
test domDoc-13.1 {appendChild} {
set doc [dom parse {<root/>}]
set newNode [$doc createElement newNode]
$doc appendChild $newNode
set newNode [$doc createComment "a comment"]
$doc appendChild $newNode
set newNode [$doc createProcessingInstruction this that]
$doc appendChild $newNode
set newNode [$doc createTextNode "text"]
$doc appendChild $newNode
set result [$doc asXML -indent none]
$doc delete
set result
} {<root/><newNode/><!--a comment--><?this that?>text}
test domDoc-13.2 {appendChild} {
set doc [dom createDocumentNode]
set newNode [$doc createElement newNode]
$doc appendChild $newNode
set result [[$doc documentElement] nodeName]
$doc delete
set result
} {newNode}
test domDoc-13.3 {appendChild} {
set doc [dom createDocumentNode]
set newNode [$doc createElement newNode]
$doc appendChild $newNode
set result [[$doc documentElement] parentNode]
$doc delete
set result
} {}
test domDoc-14.1 {removeChild} {
set doc [dom parse {<root/>}]
$doc removeChild [$doc firstChild]
set result [$doc documentElement]
$doc delete
set result
} {}
test domDoc-14.2 {removeChild} {
set doc [dom parse {<!---comment on top level--><root/>}]
$doc removeChild [$doc firstChild]
set result [$doc asXML -indent none]
$doc delete
set result
} {<root/>}
test domDoc-14.3 {removeChild} {
set doc [dom createDocumentNode]
set result [catch {$doc removeChild [$doc firstChild]}]
$doc delete
set result
} {1}
test domDoc-15.1 {hasChildNodes} {
set doc [dom createDocumentNode]
set result [$doc hasChildNodes]
set newNode [$doc createElement newNode]
$doc appendChild $newNode
lappend result [$doc hasChildNodes]
$doc delete
set result
} {0 1}
test domDoc-16.1 {childNodes} {
set doc [dom parse {<?beforeRoot this?><root/><?afterRoot that?>}]
set result {}
foreach node [$doc childNodes] {
lappend result [$node nodeName]
}
$doc delete
set result
} {beforeRoot root afterRoot}
test domDoc-17.1 {ownerDocument} {
set doc [dom parse <root/>]
set result [expr {$doc == [$doc ownerDocument]}]
$doc delete
set result
} {1}
test domDoc-18.1 {appendFromList} {
set doc [dom createDocumentNode]
$doc appendFromList {elem {} {}}
set node [$doc documentElement]
set result [list [$node nodeName] [$node parentNode]]
$doc delete
set result
} {elem {}}
test domDoc-19.1 {appendXML} {
set doc [dom createDocumentNode]
$doc appendXML <test>foo<child><childchild>text</childchild></child></test>
set result [$doc asXML -indent none]
$doc delete
set result
} {<test>foo<child><childchild>text</childchild></child></test>}
test domDoc-19.2 {appendXML} {
set doc [dom createDocumentNode]
$doc appendXML <test>foo<child><childchild>text</childchild></child></test>
set result [[$doc documentElement] nodeName]
lappend result [[$doc documentElement] parentNode]
lappend result [expr {$doc == [[$doc documentElement] ownerDocument]}]
$doc delete
set result
} {test {} 1}
test domDoc-19.3 {appendXML} {
set doc [dom createDocument foo]
$doc appendXML <test>foo<child><childchild>text</childchild></child></test>
set result [[$doc documentElement] nodeName]
set result [$doc asXML -indent none]
$doc delete
set result
} {<foo/><test>foo<child><childchild>text</childchild></child></test>}
test domDoc-20.1 {selectNodes} {
set doc [dom parse {<root><child id="1"/><child id="2"/></root>}]
set result [[$doc selectNodes {root/child[2]}] getAttribute id]
$doc delete
set result
} {2}
test domDoc-20.2 {selectNodes} {
set doc [dom parse {<root><child id="1"/><child id="2"/></root>}]
set result [[$doc selectNodes {/root/child[2]}] getAttribute id]
$doc delete
set result
} {2}
test domDoc-20.3 {selectNodes} {
set doc [dom parse {<!-- Comment --><root/><?piAfterRoot value?>}]
set result [list]
foreach node [$doc selectNodes *] {
lappend result [$node nodeName]
}
set result
} {root}
test domDoc-20.4 {selectNodes} {
set doc [dom parse {<!-- Comment --><root/><?piAfterRoot value?>}]
set result [list]
foreach node [$doc selectNodes node()] {
lappend result [$node nodeType]
}
set result
} {COMMENT_NODE ELEMENT_NODE PROCESSING_INSTRUCTION_NODE}
test domDoc-20.5 {selectNodes with -namespaces option} {
set doc [dom createDocumentNS "http://tdom.org" tdom:doc]
set node [$doc selectNodes \
-namespaces {tdom http://tdom.org} \
tdom:doc]
set result [$node nodeName]
set node [$doc selectNodes \
-namespaces {myPrefix http://tdom.org} \
myPrefix:doc]
lappend result [$node nodeName]
lappend result [$doc selectNodes -namespaces {} doc typeVar]
lappend result $typeVar
$doc delete
set result
} [list tdom:doc tdom:doc "" empty]
test domDoc-20.6 {selectNodes with -namespaces option} {
set doc [dom createDocumentNS "http://tdom.org" tdom:doc]
set node [$doc selectNodes \
-namespaces {foo bar} \
-namespaces {a b c d} \
-namespaces {tdom http://tdom.org} \
tdom:doc]
set result [$node nodeName]
set node [$doc selectNodes \
-namespaces {myPrefix http://tdom.org} \
myPrefix:doc]
lappend result [$node nodeName]
lappend result [$doc selectNodes -namespaces {} doc typeVar]
lappend result $typeVar
$doc delete
set result
} [list tdom:doc tdom:doc "" empty]
test domDoc-20.7 {selectNodes with -namespaces option} {
set doc [dom createDocumentNS "http://tdom.org" tdom:doc]
catch {set node [$doc selectNodes \
-namespaces {foo bar} \
-namespaces {a b c d} \
-namespaces {wrong_not_pair} \
tdom:doc]} errMsg
$doc delete
set errMsg
} {The "-namespaces" option requires a 'prefix namespace' pairs list as argument}
test domDoc-21.1 {baseURI} {
set doc [dom createDocumentNode]
set result [$doc baseURI]
$doc delete
set result
} {}
test domDoc-21.2 {baseURI} {
set doc [dom parse -baseurl file://foo <root/>]
set result [$doc baseURI]
$doc baseURI http://that.this
lappend result [$doc baseURI]
$doc delete
set result
} {file://foo http://that.this}
namespace eval nodeCmds {
dom createNodeCmd elementNode e1
dom createNodeCmd elementNode e2
dom createNodeCmd commentNode c
dom createNodeCmd textNode t
dom createNodeCmd cdataNode cdata
dom createNodeCmd piNode pi
dom createNodeCmd parserNode parser
}
test domDoc-22.1 {appendFromScript} {
set doc [dom createDocumentNode]
$doc appendFromScript nodeCmds::e1
set result [$doc asXML -indent none]
lappend result [[$doc documentElement] nodeName]
$doc delete
set result
} {<e1/> e1}
test domDoc-22.2 {appendFromScript} {
set doc [dom parse <root/>]
$doc appendFromScript {
nodeCmds::e1
nodeCmds::e2
}
# namespace eval nodeCmds {
# $doc appendFromScript {
# e1
# e2
# }
# }
set result [$doc asXML -indent none]
foreach node [$doc selectNodes *] {
lappend result [$node parentNode]
lappend result [expr {$doc == [$node ownerDocument]}]
}
$doc delete
set result
} {<root/><e1/><e2/> {} 1 {} 1 {} 1}
test domDoc-22.3 {appendFromScript} {
set doc [dom createDocumentNode]
set nrOfNodeCmdsBefore [info commands domNode*]
$doc appendFromScript {
nodeCmds::e1
}
$doc delete
set nrOfNodeCmdsAfter [info commands domNode*]
expr {$nrOfNodeCmdsBefore == $nrOfNodeCmdsAfter}
} {1}
test domDoc-22.4 {nodeCmd called outside of *FromScript context} {
dom createNodeCmd elementNode e
catch e
} 1
test domDoc-22.5 {nodeCmd use in child interp while in nodeCmd context} {
set doc [dom createDocument this]
set root [$doc documentElement]
dom createNodeCmd elementNode thise
dom createNodeCmd textNode t
interp create childinterp
load {} tdom childinterp
childinterp eval {
dom createNodeCmd elementNode childe
dom createNodeCmd textNode t
}
set result [catch {$root appendFromScript {
thise {
childinterp eval {
childe {
t "other"
}
}
t "some"
}
}}]
$doc delete
interp delete childinterp
set result
} {1}
test domDoc-22.6 {nodeCmd use in child interp while in nodeCmd context} {
set doc [dom createDocument this]
set root [$doc documentElement]
dom createNodeCmd elementNode thise
dom createNodeCmd textNode t
interp create childinterp
load {} tdom childinterp
childinterp eval {
dom createNodeCmd elementNode childe
dom createNodeCmd textNode t
set doc [dom createDocument child]
set root [$doc documentElement]
}
$root appendFromScript {
thise {
childinterp eval {
$root appendFromScript {
childe {
t "other"
}
}
}
t "some"
}
}
set result [$doc asXML -indent none]
append result [childinterp eval {$doc asXML -indent none}]
$doc delete
interp delete childinterp
set result
} {<this><thise>some</thise></this><child><childe>other</childe></child>}
test domDoc-23.1 {getElementsByTagNameNS} {
dom createNodeCmd elementNode child
set doc [dom createDocument root]
$doc documentElement root
$root appendFromScript {
for {set x 0} {$x < 250} {incr x} {
child [list xmlns ns$x] {}
}
}
set xml [$doc asXML]
$doc delete
set doc [dom parse $xml]
set result 1
for {set x 0} {$x < 250} {incr x} {
set nodes [$doc getElementsByTagNameNS ns$x *]
if {[llength $nodes] != 1} {
set result 0
}
}
$doc delete
set result
} {1}
test domDoc-24.1 {cdataSectionElements} {
set doc [dom parse {<root>Some Text</root>}]
set result [catch {$doc cdataSectionElements} errMsg]
lappend result $errMsg
$doc delete
set result
} {1 {wrong # args: should be "<domDoc> cdataSectionElements ?URI:?localname ?boolean?"}}
test domDoc-24.2 {cdataSectionElements} {
set doc [dom parse {<root>Some Text</root>}]
set result [catch {$doc cdataSectionElements foo bar grill} errMsg]
lappend result $errMsg
$doc delete
set result
} {1 {wrong # args: should be "<domDoc> cdataSectionElements ?URI:?localname ?boolean?"}}
test domDoc-24.3 {cdataSectionElements} {
set doc [dom parse {<root>Some Text</root>}]
set result [catch {$doc cdataSectionElements root foo} errMsg]
lappend result $errMsg
$doc delete
set result
} {1 {expected boolean value but got "foo"}}
test domDoc-24.4 {cdataSectionElements} {
set doc [dom parse {<root>Some Text</root>}]
set result [$doc cdataSectionElements root]
$doc delete
set result
} {0}
test domDoc-24.5 {cdataSectionElements} {
set doc [dom parse {<root>Some Text</root>}]
set result [$doc cdataSectionElements root 0]
lappend result [$doc cdataSectionElements root 1]
lappend result [$doc cdataSectionElements root 0]
$doc delete
set result
} {0 1 0}
test domDoc-24.6 {cdataSectionElements} {
set doc [dom parse {<root>Some Text</root>}]
set result [$doc cdataSectionElements root 1]
lappend result [$doc asXML -indent none]
$doc delete
set result
} {1 {<root><![CDATA[Some Text]]></root>}}
test domDoc-24.7 {cdataSectionElements} {
set doc [dom parse {<root><foo></root>}]
foreach element {foo root bar grill} {
$doc cdataSectionElements $element 1
}
set result [$doc asXML -indent none]
$doc delete
set result
} {<root><![CDATA[<foo>]]></root>}
test domDoc-24.8 {cdataSectionElements} {
set doc [dom parse {<root>text ]</root>}]
$doc cdataSectionElements root 1
set result [$doc asXML -indent none]
$doc delete
set result
} {<root><![CDATA[text ]]]></root>}
test domDoc-24.9 {cdataSectionElements} {
set doc [dom parse {<root>text ]]</root>}]
$doc cdataSectionElements root 1
set result [$doc asXML -indent none]
$doc delete
set result
} {<root><![CDATA[text ]]]]></root>}
test domDoc-24.10 {cdataSectionElements} {
set doc [dom parse {<root>text ]]></root>}]
$doc cdataSectionElements root 1
set result [$doc asXML -indent none]
$doc delete
set result
} {<root><![CDATA[text ]]]]><![CDATA[>]]></root>}
test domDoc-24.11 {cdataSectionElements} {
set doc [dom parse {<root>text ]]> text]]>text</root>}]
$doc cdataSectionElements root 1
set result [$doc asXML -indent none]
$doc delete
set result
} {<root><![CDATA[text ]]]]><![CDATA[> text]]]]><![CDATA[>text]]></root>}
test domDoc-24.12 {cdataSectionElements} {
set doc [dom parse {<root xmlns="http://foo.bar">text</root>}]
$doc cdataSectionElements http://foo.bar:root 1
set result [$doc asXML -indent none]
$doc delete
set result
} {<root xmlns="http://foo.bar"><![CDATA[text]]></root>}
test domDoc-24.13 {cdataSectionElements} {
set doc [dom parse {<root>text</root>}]
set result [$doc cdataSectionElements ""]
$doc delete
set result
} {0}
test domDoc-24.14 {cdataSectionElements} {
set doc [dom parse {<root>text</root>}]
set result [$doc cdataSectionElements *]
$doc delete
set result
} {}
test domDoc-24.15 {cdataSectionElements} {
set doc [dom parse {<root>text</root>}]
foreach elem {foo bar grill root http://www.foo.org:baz} {
$doc cdataSectionElements $elem 1
}
foreach elem {foo grill} {
$doc cdataSectionElements $elem 0
}
set result [lsort [$doc cdataSectionElements *]]
$doc delete
set result
} {bar http://www.foo.org:baz root}
test domDoc-24.16 {cdataSectionElements} {
set doc [dom parse {<doc><child>some text</child></doc>}]
$doc documentElement root
set node [$root firstChild]
$doc cdataSectionElements child 1
set result [$node asXML -indent none]
$doc delete
set result
} {<child><![CDATA[some text]]></child>}
test domDoc-24.17 {cdataSectionElements} {
set doc [dom parse {<doc><child>some text <b>more text</b> text again</child></doc>}]
$doc cdataSectionElements child 1
set result [$doc asXML -indent none]
$doc delete
set result
} {<doc><child><![CDATA[some text ]]><b>more text</b><![CDATA[ text again]]></child></doc>}
test domDoc-25.1 {selectNodesNamespaces} {
set doc [dom createDocument foo]
set result [$doc selectNodesNamespaces]
$doc delete
set result
} {}
test domDoc-25.2 {selectNodesNamespaces} {
set doc [dom createDocument foo]
set result [list [$doc selectNodesNamespaces] \
[$doc selectNodesNamespaces {}] \
[$doc selectNodesNamespaces]]
$doc delete
set result
} {{} {} {}}
test domDoc-25.3 {selectNodesNamespaces} {
set doc [dom createDocument foo]
set result [list [$doc selectNodesNamespaces] \
[$doc selectNodesNamespaces {prefix http://foo.org/uri}] \
[$doc selectNodesNamespaces] \
[$doc selectNodesNamespaces {}]]
$doc delete
set result
} {{} {prefix http://foo.org/uri} {prefix http://foo.org/uri} {}}
test domDoc-25.4 {selectNodesNamespaces} {
set doc [dom createDocument foo]
set result [catch {$doc selectNodesNamespaces wrong} errMsg]
lappend result $errMsg
$doc delete
set result
} {1 {The optional argument to selectNodesNamespaces must be a 'prefix namespace' pairs list}}
test domDoc-25.5 {selectNodesNamespaces} {
set doc [dom parse {<root xmlns="rootdefaultNS">
<elem1 xmlns="elem1NS"><elem11/></elem1>
<elem2 xmlns="elem2NS"/>
</root>}]
$doc selectNodesNamespaces {default1 rootdefaultNS}
set node [$doc selectNodes default1:root]
set result [list [$node prefix] [$node localName]]
$doc delete
set result
} {{} root}
test domDoc-25.6 {selectNodesNamespaces} {
set doc [dom parse {<root xmlns="rootdefaultNS">
<elem1 xmlns="elem1NS"><elem11/></elem1>
<elem2 xmlns="elem2NS"/>
</root>}]
$doc selectNodesNamespaces {default2 elem1NS default1 rootdefaultNS}
set node [$doc selectNodes default1:root/default2:elem1]
set result [list [$node prefix] [$node localName]]
set node [$doc selectNodes default1:root/default2:elem1/default2:elem11]
lappend result [$node nodeName] [$node namespaceURI]
$doc delete
set result
} {{} elem1 elem11 elem1NS}
test domDoc-25.7 {selectNodesNamespaces} {
set doc [dom parse {<root xmlns="rootdefaultNS">
<elem1 xmlns="elem1NS"><elem11 xmlns=""/></elem1>
<elem2 xmlns="elem2NS"/>
</root>}]
$doc selectNodesNamespaces {default2 elem1NS default1 rootdefaultNS}
set node [$doc selectNodes default1:root/default2:elem1]
set result [list [$node prefix] [$node localName]]
set node [$doc selectNodes default1:root/default2:elem1/elem11]
lappend result [$node nodeName] [$node namespaceURI]
$doc delete
set result
} {{} elem1 elem11 {}}
test domDoc-25.7.1 {selectNodesNamespaces} {
set doc [dom parse {<root xmlns="rootdefaultNS">
<elem1 xmlns="elem1NS"/>
<elem2 xmlns="elem2NS"/>
</root>}]
$doc documentElement root
$root firstChild elem1
$doc createElement elem11 elem11
$elem1 appendChild $elem11
$doc selectNodesNamespaces {default2 elem1NS default1 rootdefaultNS}
set node [$doc selectNodes default1:root/default2:elem1]
set result [list [$node prefix] [$node localName]]
set node [$doc selectNodes default1:root/default2:elem1/elem11]
lappend result [$node nodeName] [$node namespaceURI]
$doc delete
set result
} {{} elem1 elem11 {}}
test domDoc-25.8 {selectNodesNamespaces} {
set doc [dom parse {<root xmlns="rootdefaultNS">
<elem1 xmlns="elem1NS"><elem11 xmlns=""/></elem1>
<elem2 xmlns="elem2NS"/>
</root>}]
$doc selectNodesNamespaces {default2 elem1NS default1 rootdefaultNS}
set result [catch {set node [$doc selectNodes \
-namespaces {
dflt1 elem1NS
dflt2 rootdefaultNS
} \
default1:root/dflt1:elem1/elem11]} errMsg]
lappend result $errMsg
$doc delete
set result
} {1 {Prefix doesn't resolve}}
test domDoc-25.9 {selectNodesNamespaces} {
set doc [dom parse {<root xmlns="rootdefaultNS">
<elem1 xmlns="elem1NS"><elem11 xmlns=""/></elem1>
<elem2 xmlns="elem2NS"/>
</root>}]
$doc selectNodesNamespaces {default2 elem1NS default1 rootdefaultNS}
set node [$doc selectNodes default1:root/default2:elem1]
set result [list [$node prefix] [$node localName]]
set node [$doc selectNodes \
-namespaces {dflt1 elem1NS dflt2 rootdefaultNS} \
dflt2:root/dflt1:elem1/elem11]
lappend result [$node nodeName] [$node namespaceURI]
$doc delete
set result
} {{} elem1 elem11 {}}
test domDoc-26.1 {Fragment list} {
set doc [dom parse {<!---comment on top level-->
<root>text1<child>text2</child>text3</root>}]
$doc removeChild [$doc firstChild]
$doc documentElement root
for {set i 1} {$i < 4} {incr i} {
set removedNode$i [$root removeChild [$root firstChild]]
}
$removedNode2 delete
$root appendChild $removedNode3
$root appendChild $removedNode1
set result [$doc asXML -indent none]
$doc delete
set result
} {<root>text3text1</root>}
test domDoc-27.1 {deleteXPathCache} {
set doc [dom createDocument doc]
set result [list]
lappend result [$doc deleteXPathCache foo/bar]
$doc selectNodes -cache 1 2+2
lappend result [$doc deleteXPathCache foo/bar]
lappend result [$doc deleteXPathCache 2+2]
lappend result [$doc deleteXPathCache]
$doc selectNodes -cache 1 2+2
$doc delete
set result
} {{} {} {} {}}
test domDoc-28.1 {createElementNS} {
set doc [dom createDocument doc]
set newElem [$doc createElementNS uri ns:e]
$doc documentElement root
$root appendChild $newElem
set result [$doc asXML -indent none]
$doc delete
set result
} {<doc><ns:e xmlns:ns="uri"/></doc>}
test domDoc-28.2 {createElementNS} {
set doc [dom createDocument doc]
set newElem [$doc createElementNS uri ns:e]
$newElem setAttributeNS uri ns:att value
$doc documentElement root
$root appendChild $newElem
set result [$doc selectNodes -namespaces {ns uri} string(/doc/ns:e/@ns:att)]
$doc delete
set result
} {value}
test domDoc-28.3 {createElementNS} {
set doc [dom createDocument doc]
catch {$doc createElementNS "" e} errMsg
$doc delete
set errMsg
} {Missing URI in Namespace declaration}
# cleanup
::tcltest::cleanupTests
return
|