| 1 61 62 63 package org.jaxen; 64 65 import java.io.File ; 66 import java.io.IOException ; 67 import java.util.Iterator ; 68 import java.util.List ; 69 70 import javax.xml.parsers.DocumentBuilder ; 71 import javax.xml.parsers.DocumentBuilderFactory ; 72 import javax.xml.parsers.ParserConfigurationException ; 73 74 import org.jaxen.dom.DOMXPath; 75 import org.jaxen.dom.NamespaceNode; 76 import org.jaxen.pattern.Pattern; 77 import org.w3c.dom.Attr ; 78 import org.w3c.dom.Element ; 79 import org.w3c.dom.Node ; 80 import org.w3c.dom.Text ; 81 import org.xml.sax.SAXException ; 82 83 import junit.framework.TestCase; 84 85 94 public class BaseXPathTest extends TestCase { 95 96 private org.w3c.dom.Document doc; 97 private DocumentBuilder builder; 98 99 public BaseXPathTest(String name) { 100 super(name); 101 } 102 103 protected void setUp() throws ParserConfigurationException { 104 105 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 106 factory.setNamespaceAware(true); 107 doc = factory.newDocumentBuilder().newDocument(); 108 builder = factory.newDocumentBuilder(); 109 110 } 111 112 public void testSelectSingleNodeForContext() throws JaxenException { 113 114 BaseXPath xpath = new BaseXPath("1 + 2"); 115 116 String stringValue = xpath.stringValueOf(xpath); 117 assertEquals("3", stringValue); 118 119 Number numberValue = xpath.numberValueOf(xpath); 120 assertEquals(3, numberValue.doubleValue(), 0.00001); 121 122 } 123 124 125 public void testParentOfSelection() throws JaxenException { 126 133 XPath xpath = new DOMXPath("(/html/a/img[contains(@src,'gif')])[2]/.."); 134 org.w3c.dom.Element html = doc.createElementNS("", "html"); 135 org.w3c.dom.Element a1 = doc.createElementNS("", "a"); 136 org.w3c.dom.Element a2 = doc.createElementNS("", "a"); 137 org.w3c.dom.Element img1 = doc.createElementNS("", "img"); 138 org.w3c.dom.Attr img1_src = doc.createAttributeNS("", "src"); 139 img1_src.setValue("1.gif"); 140 org.w3c.dom.Element img2 = doc.createElementNS("", "img"); 141 org.w3c.dom.Attr img2_src = doc.createAttributeNS("", "src"); 142 img2_src.setValue("2.gif"); 143 144 img1.setAttributeNode(img1_src); 145 img2.setAttributeNode(img2_src); 146 a1.appendChild(img1); 147 a2.appendChild(img2); 148 html.appendChild(a1); 149 html.appendChild(a2); 150 doc.appendChild(html); 151 152 List result = xpath.selectNodes(doc); 153 assertEquals(1, result.size()); 154 assertEquals(a2, result.get(0)); 155 } 156 157 158 159 160 public void testEvaluateString() throws JaxenException { 161 162 BaseXPath xpath = new DOMXPath("string(/*)"); 163 164 doc.appendChild(doc.createElement("root")); 165 String stringValue = (String ) xpath.evaluate(doc); 166 assertEquals("", stringValue); 167 168 } 169 170 171 public void testNumberValueOfEmptyNodeSetIsNaN() throws JaxenException { 172 173 BaseXPath xpath = new DOMXPath("/x"); 174 175 doc.appendChild(doc.createElement("root")); 176 Double numberValue = (Double ) xpath.numberValueOf(doc); 177 assertTrue(numberValue.isNaN()); 178 179 } 180 181 182 public void testPathWithParentheses() throws JaxenException { 183 184 BaseXPath xpath = new DOMXPath("(/root)/child"); 185 186 Element root = doc.createElement("root"); 187 doc.appendChild(root); 188 Element child = doc.createElement("child"); 189 root.appendChild(child); 190 191 assertEquals(child, xpath.selectSingleNode(doc)); 192 193 } 194 195 196 public void testEvaluateWithMultiNodeAnswer() throws JaxenException { 197 198 BaseXPath xpath = new DOMXPath("(/descendant-or-self::node())"); 199 200 doc.appendChild(doc.createElement("root")); 201 List result = (List ) xpath.evaluate(doc); 202 assertEquals(2, result.size()); 203 204 } 205 206 207 public void testValueOfEmptyListIsEmptyString() throws JaxenException { 208 209 BaseXPath xpath = new DOMXPath("/element"); 210 doc.appendChild(doc.createElement("root")); 211 212 String stringValue = xpath.stringValueOf(doc); 213 assertEquals("", stringValue); 214 215 } 216 217 public void testAllNodesQuery() throws JaxenException { 218 219 BaseXPath xpath = new DOMXPath("//. | /"); 220 org.w3c.dom.Element root = doc.createElementNS("http://www.example.org/", "root"); 221 doc.appendChild(root); 222 223 String stringValue = xpath.stringValueOf(doc); 224 assertEquals("", stringValue); 225 226 } 227 228 229 public void testAncestorAxis() throws JaxenException { 230 231 BaseXPath xpath = new DOMXPath("ancestor::*"); 232 org.w3c.dom.Element root = doc.createElementNS("", "root"); 233 org.w3c.dom.Element parent = doc.createElementNS("", "parent"); 234 doc.appendChild(root); 235 org.w3c.dom.Element child = doc.createElementNS("", "child"); 236 root.appendChild(parent); 237 parent.appendChild(child); 238 239 List result = xpath.selectNodes(child); 240 assertEquals(2, result.size()); 241 assertEquals(root, result.get(0)); 242 assertEquals(parent, result.get(1)); 243 244 } 245 246 247 public void testPrecedingSiblingAxisIsInDocumentOrder() throws JaxenException { 248 249 BaseXPath xpath = new DOMXPath("preceding-sibling::*"); 250 org.w3c.dom.Element root = doc.createElementNS("", "root"); 251 doc.appendChild(root); 252 org.w3c.dom.Element child1 = doc.createElementNS("", "child1"); 253 root.appendChild(child1); 254 org.w3c.dom.Element child2 = doc.createElementNS("", "child2"); 255 root.appendChild(child2); 256 org.w3c.dom.Element child3 = doc.createElementNS("", "child3"); 257 root.appendChild(child3); 258 259 List result = xpath.selectNodes(child3); 260 assertEquals(2, result.size()); 261 assertEquals(child1, result.get(0)); 262 assertEquals(child2, result.get(1)); 263 264 } 265 266 267 public void testPrecedingAxisIsInDocumentOrder() throws JaxenException { 268 269 BaseXPath xpath = new DOMXPath("preceding::*"); 270 org.w3c.dom.Element root = doc.createElementNS("", "root"); 271 doc.appendChild(root); 272 org.w3c.dom.Element parent1 = doc.createElementNS("", "parent1"); 273 root.appendChild(parent1); 274 org.w3c.dom.Element parent2 = doc.createElementNS("", "parent2"); 275 root.appendChild(parent2); 276 org.w3c.dom.Element child1 = doc.createElementNS("", "child1"); 277 parent2.appendChild(child1); 278 org.w3c.dom.Element child2 = doc.createElementNS("", "child2"); 279 parent2.appendChild(child2); 280 org.w3c.dom.Element child3 = doc.createElementNS("", "child3"); 281 parent2.appendChild(child3); 282 283 List result = xpath.selectNodes(child3); 284 assertEquals(3, result.size()); 285 assertEquals(parent1, result.get(0)); 286 assertEquals(child1, result.get(1)); 287 assertEquals(child2, result.get(2)); 288 289 } 290 291 292 public void testPrecedingAxisWithPositionalPredicate() throws JaxenException { 293 294 BaseXPath xpath = new DOMXPath("preceding::*[1]"); 295 org.w3c.dom.Element root = doc.createElementNS("", "root"); 296 doc.appendChild(root); 297 org.w3c.dom.Element child1 = doc.createElementNS("", "child1"); 298 root.appendChild(child1); 299 org.w3c.dom.Element child2 = doc.createElementNS("", "child2"); 300 root.appendChild(child2); 301 org.w3c.dom.Element child3 = doc.createElementNS("", "child3"); 302 root.appendChild(child3); 303 304 List result = xpath.selectNodes(child3); 305 assertEquals(1, result.size()); 306 assertEquals(child2, result.get(0)); 307 308 } 309 310 311 public void testAncestorAxisWithPositionalPredicate() throws JaxenException { 312 313 BaseXPath xpath = new DOMXPath("ancestor::*[1]"); 314 org.w3c.dom.Element root = doc.createElementNS("", "root"); 315 doc.appendChild(root); 316 org.w3c.dom.Element child1 = doc.createElementNS("", "child1"); 317 root.appendChild(child1); 318 org.w3c.dom.Element child2 = doc.createElementNS("", "child2"); 319 child1.appendChild(child2); 320 org.w3c.dom.Element child3 = doc.createElementNS("", "child3"); 321 child2.appendChild(child3); 322 323 List result = xpath.selectNodes(child3); 324 assertEquals(1, result.size()); 325 assertEquals(child2, result.get(0)); 326 327 } 328 329 330 public void testAncestorOrSelfAxis() throws JaxenException { 331 332 BaseXPath xpath = new DOMXPath("ancestor-or-self::*"); 333 org.w3c.dom.Element root = doc.createElementNS("", "root"); 334 org.w3c.dom.Element parent = doc.createElementNS("", "parent"); 335 doc.appendChild(root); 336 org.w3c.dom.Element child = doc.createElementNS("", "child"); 337 root.appendChild(parent); 338 parent.appendChild(child); 339 340 List result = xpath.selectNodes(child); 341 assertEquals(3, result.size()); 342 assertEquals(root, result.get(0)); 343 assertEquals(parent, result.get(1)); 344 assertEquals(child, result.get(2)); 345 346 } 347 348 349 public void testAbbreviatedDoubleSlashAxis() throws JaxenException { 351 352 BaseXPath xpath = new DOMXPath("//x"); 353 org.w3c.dom.Element a = doc.createElementNS("", "a"); 354 org.w3c.dom.Element b = doc.createElementNS("", "b"); 355 doc.appendChild(a); 356 org.w3c.dom.Element x1 = doc.createElementNS("", "x"); 357 x1.appendChild(doc.createTextNode("1")); 358 a.appendChild(x1); 359 a.appendChild(b); 360 org.w3c.dom.Element x2 = doc.createElementNS("", "x"); 361 org.w3c.dom.Element x3 = doc.createElementNS("", "x"); 362 org.w3c.dom.Element x4 = doc.createElementNS("", "x"); 363 a.appendChild(x4); 364 b.appendChild(x2); 365 b.appendChild(x3); 366 x2.appendChild(doc.createTextNode("2")); 367 x3.appendChild(doc.createTextNode("3")); 368 x4.appendChild(doc.createTextNode("4")); 369 370 List result = xpath.selectNodes(doc); 371 assertEquals(4, result.size()); 372 assertEquals(x1, result.get(0)); 373 assertEquals(x2, result.get(1)); 374 assertEquals(x3, result.get(2)); 375 assertEquals(x4, result.get(3)); 376 377 } 378 379 380 public void testAncestorFollowedByChildren() throws JaxenException { 382 383 BaseXPath xpath = new DOMXPath("/a/b/x/ancestor::*/child::x"); 384 org.w3c.dom.Element a = doc.createElementNS("", "a"); 385 org.w3c.dom.Element b = doc.createElementNS("", "b"); 386 doc.appendChild(a); 387 org.w3c.dom.Element x1 = doc.createElementNS("", "x"); 388 x1.appendChild(doc.createTextNode("1")); 389 a.appendChild(x1); 390 a.appendChild(b); 391 org.w3c.dom.Element x2 = doc.createElementNS("", "x"); 392 org.w3c.dom.Element x3 = doc.createElementNS("", "x"); 393 org.w3c.dom.Element x4 = doc.createElementNS("", "x"); 394 a.appendChild(x4); 395 b.appendChild(x2); 396 b.appendChild(x3); 397 x2.appendChild(doc.createTextNode("2")); 398 x3.appendChild(doc.createTextNode("3")); 399 x4.appendChild(doc.createTextNode("4")); 400 401 List result = xpath.selectNodes(doc); 402 assertEquals(4, result.size()); 403 assertEquals(x1, result.get(0)); 404 assertEquals(x2, result.get(1)); 405 assertEquals(x3, result.get(2)); 406 assertEquals(x4, result.get(3)); 407 408 } 409 410 411 public void testDescendantAxis() throws JaxenException { 413 414 BaseXPath xpath = new DOMXPath("/descendant::x"); 415 org.w3c.dom.Element a = doc.createElementNS("", "a"); 416 org.w3c.dom.Element b = doc.createElementNS("", "b"); 417 doc.appendChild(a); 418 org.w3c.dom.Element x1 = doc.createElementNS("", "x"); 419 x1.appendChild(doc.createTextNode("1")); 420 a.appendChild(x1); 421 a.appendChild(b); 422 org.w3c.dom.Element x2 = doc.createElementNS("", "x"); 423 org.w3c.dom.Element x3 = doc.createElementNS("", "x"); 424 org.w3c.dom.Element x4 = doc.createElementNS("", "x"); 425 a.appendChild(x4); 426 b.appendChild(x2); 427 b.appendChild(x3); 428 x2.appendChild(doc.createTextNode("2")); 429 x3.appendChild(doc.createTextNode("3")); 430 x4.appendChild(doc.createTextNode("4")); 431 432 List result = xpath.selectNodes(doc); 433 assertEquals(4, result.size()); 434 assertEquals(x1, result.get(0)); 435 assertEquals(x2, result.get(1)); 436 assertEquals(x3, result.get(2)); 437 assertEquals(x4, result.get(3)); 438 439 } 440 441 public void testDescendantAxisWithAttributes() throws JaxenException { 442 443 BaseXPath xpath = new DOMXPath("/descendant::x/@*"); 444 org.w3c.dom.Element a = doc.createElementNS("", "a"); 445 org.w3c.dom.Element b = doc.createElementNS("", "b"); 446 doc.appendChild(a); 447 org.w3c.dom.Element x1 = doc.createElementNS("", "x"); 448 a.appendChild(x1); 449 a.appendChild(b); 450 org.w3c.dom.Element x2 = doc.createElementNS("", "x"); 451 org.w3c.dom.Element x3 = doc.createElementNS("", "x"); 452 org.w3c.dom.Element x4 = doc.createElementNS("", "x"); 453 a.appendChild(x4); 454 b.appendChild(x2); 455 b.appendChild(x3); 456 457 Attr a1 = doc.createAttribute("name"); 458 a1.setNodeValue("1"); 459 x1.setAttributeNode(a1); 460 Attr a2 = doc.createAttribute("name"); 461 a2.setNodeValue("2"); 462 x2.setAttributeNode(a2); 463 Attr a3 = doc.createAttribute("name"); 464 a3.setNodeValue("3"); 465 x3.setAttributeNode(a3); 466 Attr a4 = doc.createAttribute("name"); 467 a4.setNodeValue("4"); 468 x4.setAttributeNode(a4); 469 470 List result = xpath.selectNodes(doc); 471 assertEquals(4, result.size()); 472 assertEquals(a1, result.get(0)); 473 assertEquals(a2, result.get(1)); 474 assertEquals(a3, result.get(2)); 475 assertEquals(a4, result.get(3)); 476 477 } 478 479 public void testDescendantAxisWithNamespaceNodes() throws JaxenException { 480 481 BaseXPath xpath = new DOMXPath("/descendant::x/namespace::node()"); 482 org.w3c.dom.Element a = doc.createElementNS("", "a"); 483 org.w3c.dom.Element b = doc.createElementNS("", "b"); 484 doc.appendChild(a); 485 org.w3c.dom.Element x1 = doc.createElementNS("", "x"); 486 a.appendChild(x1); 487 a.appendChild(b); 488 org.w3c.dom.Element x2 = doc.createElementNS("", "x"); 489 org.w3c.dom.Element x3 = doc.createElementNS("", "x"); 490 org.w3c.dom.Element x4 = doc.createElementNS("", "x"); 491 a.appendChild(x4); 492 b.appendChild(x2); 493 b.appendChild(x3); 494 495 Attr a1 = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:a"); 496 a1.setNodeValue("http://www.example.org/"); 497 x1.setAttributeNode(a1); 498 Attr a2 = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:b"); 499 a2.setNodeValue("http://www.example.org/"); 500 x2.setAttributeNode(a2); 501 Attr a3 = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:c"); 502 a3.setNodeValue("http://www.example.org/"); 503 x3.setAttributeNode(a3); 504 Attr a4 = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:d"); 505 a4.setNodeValue("http://www.example.org/"); 506 x4.setAttributeNode(a4); 507 508 List result = xpath.selectNodes(doc); 509 assertEquals(8, result.size()); 510 Iterator iterator = result.iterator(); 511 StringBuffer sb = new StringBuffer (4); 512 while (iterator.hasNext()) { 513 NamespaceNode ns = (NamespaceNode) iterator.next(); 514 if (ns.getNodeValue().equals("http://www.example.org/")) { 515 String name = ns.getNodeName(); 516 sb.append(name); 517 } 518 } 519 assertEquals("abcd", sb.toString()); 520 521 } 522 523 public void testMultipleAttributesOnElement() throws JaxenException { 524 525 BaseXPath xpath = new DOMXPath("/descendant::x/@*"); 526 org.w3c.dom.Element a = doc.createElementNS("", "a"); 527 org.w3c.dom.Element b = doc.createElementNS("", "b"); 528 doc.appendChild(a); 529 org.w3c.dom.Element x1 = doc.createElementNS("", "x"); 530 a.appendChild(x1); 531 a.appendChild(b); 532 533 Attr a1 = doc.createAttribute("name1"); 534 a1.setNodeValue("1"); 535 x1.setAttributeNode(a1); 536 Attr a2 = doc.createAttribute("name2"); 537 a2.setNodeValue("2"); 538 x1.setAttributeNode(a2); 539 Attr a3 = doc.createAttribute("name3"); 540 a3.setNodeValue("3"); 541 x1.setAttributeNode(a3); 542 Attr a4 = doc.createAttribute("name4"); 543 a4.setNodeValue("4"); 544 x1.setAttributeNode(a4); 545 546 List result = xpath.selectNodes(doc); 547 assertEquals(4, result.size()); 548 assertTrue(result.contains(a1)); 549 assertTrue(result.contains(a2)); 550 assertTrue(result.contains(a3)); 551 assertTrue(result.contains(a4)); 552 553 } 554 555 public void testXMLNamespaceAttributeOrderOnAncestorAxis() 556 throws JaxenException { 557 558 org.w3c.dom.Element superroot = doc.createElement("superroot"); 559 doc.appendChild(superroot); 560 org.w3c.dom.Element root = doc.createElement("root"); 561 superroot.appendChild(root); 562 563 org.w3c.dom.Attr p0 = doc.createAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:id"); 564 p0.setValue("p0"); 565 superroot.setAttributeNodeNS(p0); 566 org.w3c.dom.Attr p1 = doc.createAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:id"); 567 p1.setValue("p1"); 568 root.setAttributeNodeNS(p1); 569 570 org.w3c.dom.Element child = doc.createElement("child312"); 571 root.appendChild(child); 572 573 BaseXPath xpath = new DOMXPath("ancestor::*/@xml:*"); 574 List result = xpath.selectNodes(child); 575 assertEquals(2, result.size()); 576 assertEquals(p0, result.get(0)); 577 assertEquals(p1, result.get(1)); 578 579 } 580 581 public void testDescendantAxisWithAttributesAndChildren() throws JaxenException { 582 583 BaseXPath xpath = new DOMXPath("/descendant::x/@* | /descendant::x"); 584 org.w3c.dom.Element a = doc.createElementNS("", "a"); 585 org.w3c.dom.Element b = doc.createElementNS("", "b"); 586 doc.appendChild(a); 587 org.w3c.dom.Element x1 = doc.createElementNS("", "x"); 588 a.appendChild(x1); 589 a.appendChild(b); 590 org.w3c.dom.Element x2 = doc.createElementNS("", "x"); 591 org.w3c.dom.Element x3 = doc.createElementNS("", "x"); 592 org.w3c.dom.Element x4 = doc.createElementNS("", "x"); 593 a.appendChild(x4); 594 b.appendChild(x2); 595 b.appendChild(x3); 596 597 Attr a1 = doc.createAttribute("name"); 598 a1.setNodeValue("1"); 599 x1.setAttributeNode(a1); 600 Attr a2 = doc.createAttribute("name"); 601 a2.setNodeValue("2"); 602 x2.setAttributeNode(a2); 603 Attr a3 = doc.createAttribute("name"); 604 a3.setNodeValue("3"); 605 x3.setAttributeNode(a3); 606 Attr a4 = doc.createAttribute("name"); 607 a4.setNodeValue("4"); 608 x4.setAttributeNode(a4); 609 610 List result = xpath.selectNodes(doc); 611 assertEquals(8, result.size()); 612 assertEquals(x1, result.get(0)); 613 assertEquals(a1, result.get(1)); 614 assertEquals(x2, result.get(2)); 615 assertEquals(a2, result.get(3)); 616 assertEquals(x3, result.get(4)); 617 assertEquals(a3, result.get(5)); 618 assertEquals(x4, result.get(6)); 619 assertEquals(a4, result.get(7)); 620 621 } 622 623 public void testAncestorAxisWithAttributes() throws JaxenException { 624 625 BaseXPath xpath = new DOMXPath("ancestor::*/@*"); 626 org.w3c.dom.Element a = doc.createElementNS("", "a"); 627 org.w3c.dom.Element b = doc.createElementNS("", "b"); 628 doc.appendChild(a); 629 a.appendChild(b); 630 org.w3c.dom.Element x3 = doc.createElementNS("", "x"); 631 b.appendChild(x3); 632 633 Attr a1 = doc.createAttribute("name"); 634 a1.setNodeValue("1"); 635 a.setAttributeNode(a1); 636 Attr a2 = doc.createAttribute("name"); 637 a2.setNodeValue("2"); 638 b.setAttributeNode(a2); 639 Attr a3 = doc.createAttribute("name"); 640 x3.setNodeValue("3"); 641 x3.setAttributeNode(a3); 642 643 List result = xpath.selectNodes(x3); 644 assertEquals(2, result.size()); 645 assertEquals(a1, result.get(0)); 646 assertEquals(a2, result.get(1)); 647 648 } 649 650 public void testPrincipalNodeTypeOfSelfAxisIsElement() throws JaxenException { 652 653 BaseXPath xpath = new DOMXPath("child/@*[self::test]"); 654 org.w3c.dom.Element a = doc.createElementNS("", "child"); 655 org.w3c.dom.Attr test = doc.createAttributeNS("", "test"); 656 test.setValue("value"); 657 a.setAttributeNode(test); 658 doc.appendChild(a); 659 660 List result = xpath.selectNodes(doc); 661 assertEquals(0, result.size()); 662 663 } 664 665 public void testSelfAxisWithNodeTestCanReturnNonPrincipalNodeType() throws JaxenException { 667 668 BaseXPath xpath = new DOMXPath("child/@*[self::node()]"); 669 org.w3c.dom.Element a = doc.createElementNS("", "child"); 670 org.w3c.dom.Attr test = doc.createAttributeNS("", "test"); 671 test.setValue("value"); 672 a.setAttributeNode(test); 673 doc.appendChild(a); 674 675 List result = xpath.selectNodes(doc); 676 assertEquals(1, result.size()); 677 678 } 679 680 public void testDescendantOrSelfAxis() throws JaxenException { 683 684 BaseXPath xpath = new DOMXPath("/descendant-or-self::x"); 685 org.w3c.dom.Element a = doc.createElementNS("", "a"); 686 org.w3c.dom.Element b = doc.createElementNS("", "b"); 687 doc.appendChild(a); 688 org.w3c.dom.Element x1 = doc.createElementNS("", "x"); 689 x1.appendChild(doc.createTextNode("1")); 690 a.appendChild(x1); 691 a.appendChild(b); 692 org.w3c.dom.Element x2 = doc.createElementNS("", "x"); 693 org.w3c.dom.Element x3 = doc.createElementNS("", "x"); 694 org.w3c.dom.Element x4 = doc.createElementNS("", "x"); 695 a.appendChild(x4); 696 b.appendChild(x2); 697 b.appendChild(x3); 698 x2.appendChild(doc.createTextNode("2")); 699 x3.appendChild(doc.createTextNode("3")); 700 x4.appendChild(doc.createTextNode("4")); 701 702 List result = xpath.selectNodes(doc); 703 assertEquals(4, result.size()); 704 assertEquals(x1, result.get(0)); 705 assertEquals(x2, result.get(1)); 706 assertEquals(x3, result.get(2)); 707 assertEquals(x4, result.get(3)); 708 709 } 710 711 712 public void testDuplicateNodes() throws JaxenException { 713 714 BaseXPath xpath = new DOMXPath("//x | //*"); 715 org.w3c.dom.Element a = doc.createElementNS("", "a"); 716 org.w3c.dom.Element b = doc.createElementNS("", "b"); 717 doc.appendChild(a); 718 org.w3c.dom.Element x1 = doc.createElementNS("", "x"); 719 x1.appendChild(doc.createTextNode("1")); 720 a.appendChild(x1); 721 a.appendChild(b); 722 org.w3c.dom.Element x2 = doc.createElementNS("", "x"); 723 org.w3c.dom.Element x3 = doc.createElementNS("", "x"); 724 org.w3c.dom.Element x4 = doc.createElementNS("", "x"); 725 a.appendChild(x4); 726 b.appendChild(x2); 727 b.appendChild(x3); 728 x2.appendChild(doc.createTextNode("2")); 729 x3.appendChild(doc.createTextNode("3")); 730 x4.appendChild(
|