ttree_replace1.nim 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. discard """
  2. output: '''
  3. <xml>
  4. <head>
  5. <div>Some text</div>
  6. <div>Some more text </div>
  7. </head>
  8. <body>
  9. <div>Some text in body</div>
  10. <div>Some more text in body </div>
  11. </body>
  12. </xml>
  13. '''
  14. """
  15. # Test xmltree add/insert/delete/replace operations
  16. import xmlparser
  17. import xmltree
  18. var baseDocHead = """
  19. <head>
  20. <div>Some text</div>
  21. <div>Some more text </div>
  22. </head>
  23. """
  24. var baseDocHeadTree = parseXml(baseDocHead)
  25. var baseDocBody = """
  26. <body>
  27. <div>Some text in body</div>
  28. <div>Some more text in body </div>
  29. </body>
  30. """
  31. var baseDocBodyTree = parseXml(baseDocBody)
  32. let initialDocBase = """
  33. <xml>
  34. <head>
  35. <div>Some text before replace </div>
  36. <div>Some more text before replace </div>
  37. </head>
  38. <body>
  39. <div>Some text in body before replace </div>
  40. <div>Some more text in body before replace </div>
  41. </body>
  42. </xml>
  43. """
  44. var initialDocBaseTree = parseXml(initialDocBase)
  45. proc test_replace() =
  46. var testDoc = initialDocBaseTree
  47. testDoc.replace(0..1, @[baseDocHeadTree, baseDocBodyTree])
  48. echo $testDoc
  49. test_replace()