ttree_add1.nim 975 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. var bodyItems: seq[XmlNode] = @[]
  42. for item in baseDocBodyTree.items():
  43. bodyItems.add(item)
  44. newBody.add(bodyItems)
  45. echo $newBody
  46. testDoc.add(newBody)
  47. echo $testDoc
  48. test_add()