ttree_replace.nim 874 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 baseDocBody = """
  19. <body>
  20. <div>Some text in body</div>
  21. <div>Some more text in body </div>
  22. </body>
  23. """
  24. var baseDocBodyTree = parseXml(baseDocBody)
  25. let initialDocBase = """
  26. <xml>
  27. <head>
  28. <div>Some text</div>
  29. <div>Some more text </div>
  30. </head>
  31. <body>
  32. <div>Some text in body before replace </div>
  33. <div>Some more text in body before replace </div>
  34. </body>
  35. </xml>
  36. """
  37. var initialDocBaseTree = parseXml(initialDocBase)
  38. proc test_replace() =
  39. var testDoc = initialDocBaseTree
  40. testDoc.replace(1, @[baseDocBodyTree])
  41. echo $testDoc
  42. test_replace()