ttree_add.nim 912 B

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