mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 08:54:53 +00:00
* [change] add/insert/delete family of xmltree expanded with several variations. Added replace methods family * [change] Lifted child limitations on insert methods (consulted with @araq) * [tests] add/insert/replace/delete of xmltree XmlNodes tests added
52 lines
941 B
Nim
52 lines
941 B
Nim
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_insert() =
|
|
var testDoc = baseDocHeadTree
|
|
var newBody = newElement("body")
|
|
for item in baseDocBodyTree.items():
|
|
newBody.insert(item, len(newBody))
|
|
|
|
echo $newBody
|
|
|
|
testDoc.insert(newBody, 1)
|
|
echo $testDoc
|
|
|
|
test_insert()
|