domchardata.phpt 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. --TEST--
  2. CharData: DOMCharacterData and related functionality
  3. --EXTENSIONS--
  4. dom
  5. --FILE--
  6. <?php
  7. require_once("dom_test.inc");
  8. $dom = new DOMDocument;
  9. $dom->loadXML($xmlstr);
  10. if(!$dom) {
  11. echo "Error while parsing the document\n";
  12. exit;
  13. }
  14. $node = $dom->documentElement;
  15. $charnode = $dom->createElement('charnode');
  16. $node->appendChild($charnode);
  17. /* DOMComment */
  18. $comment = new DOMComment('Testing character data and extending nodes');
  19. $charnode->appendChild($comment);
  20. echo "Comment Length: ".$comment->length."\n";
  21. $comment->data = 'Updated comment';
  22. echo "New Comment Length: ".$comment->length."\n";
  23. echo "New Comment Data: ".$comment->data."\n";
  24. /* DOMCDataSection */
  25. $cdata = new DOMCDataSection('Chars: <>&"');
  26. $charnode->appendChild($cdata);
  27. echo "Substring: ".$cdata->substringData(7, 4)."\n";
  28. $cdata->replaceData(10, 1, "'");
  29. echo "New Substring: ".$cdata->substringData(7, 4)."\n";
  30. /* DOMCharacterData using DOMComment */
  31. $comment = new DOMComment('instructions');
  32. echo "Comment Value: ".$comment->data."\n";
  33. $comment->data = 'some more instructions';
  34. echo "New Comment Value: ".$comment->data."\n";
  35. $comment->insertData(10, 'pi ');
  36. $comment->replaceData(18, 5, 'i');
  37. $comment->insertData(20, 'g');
  38. $comment->deleteData(13, 2);
  39. $comment->deleteData(10, 3);
  40. $comment->insertData(10, 'comment ');
  41. echo "Updated Comment Value: ".$comment->data."\n";
  42. /* DOMText */
  43. $text = new DOMText('some text characters');
  44. echo "Whole Text: ".$text->wholeText."\n";
  45. $text2 = $text->splitText(9);
  46. echo "Split text: ".$text2->wholeText."\n";
  47. $text3 = $text2->splitText(1);
  48. echo "Is Whitespace?: ".($text2->isElementContentWhitespace()?'YES':'NO');
  49. ?>
  50. --EXPECT--
  51. Comment Length: 42
  52. New Comment Length: 15
  53. New Comment Data: Updated comment
  54. Substring: <>&"
  55. New Substring: <>&'
  56. Comment Value: instructions
  57. New Comment Value: some more instructions
  58. Updated Comment Value: some more comment strings
  59. Whole Text: some text characters
  60. Split text: characters
  61. Is Whitespace?: YES