summary refs log tree commit diff stats
path: root/tests/xml/ttree_add1.nim
blob: 30ec83c02b6bd4503037288e9f18611f81bb1753 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
discard """
  output: '''
<body>
  <div>Some text in body</div>
  <div>Some more text in body </div>
</body>
<xml>
  <head>
    <div>Some text</div>
    <div>Some more text </div>
  </head>
  <body>
    <div>Some text in body</div>
    <div>Some more text in body </div>
  </body>
</xml>
'''
"""

# Test xmltree add/insert/delete/replace operations
import xmlparser
import xmltree
var baseDocHead = """
<xml>
  <head>
    <div>Some text</div>
    <div>Some more text </div>
  </head>
</xml>
"""
var baseDocHeadTree = parseXml(baseDocHead)
var baseDocBody = """
<body>
  <div>Some text in body</div>
  <div>Some more text in body </div>
</body>
"""
var baseDocBodyTree = parseXml(baseDocBody)

proc test_add() =
  var testDoc = baseDocHeadTree
  var newBody = newElement("body")
  var bodyItems: seq[XmlNode] = @[]
  for item in baseDocBodyTree.items():
    bodyItems.add(item)
  newBody.add(bodyItems)
  
  echo $newBody
  
  testDoc.add(newBody)
  echo $testDoc

test_add()