-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathxml.cpp
More file actions
85 lines (75 loc) · 4.21 KB
/
xml.cpp
File metadata and controls
85 lines (75 loc) · 4.21 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#import "xml"
var xml_doc = new xml::document()
var root = new xml::node("root")
xml_doc.append_node(root)
var attr1 = new xml::attribute("attr1", "1")
root.append_attribute(attr1)
root.append_attribute(new xml::attribute("attr2", "2"))
root.prepend_attribute(new xml::attribute("attr3", "3"))
root.insert_attribute(attr1, new xml::attribute("attr4", "4"))
var roles = new xml::node("roles")
root.append_node(roles)
var role1 = new xml::node("role", "wanger")
roles.append_node(role1)
roles.append_node(new xml::node("role", "mazi"))
roles.prepend_node(new xml::node("role", "zhangsan"))
roles.insert_node(role1, new xml::node("role", "mazi"))
var items = new xml::node("items")
root.append_node(items)
items.append_node(new xml::node("weapon", "qinggang"))
items.append_node(new xml::node("cloth", "fengyi"))
println(xml_doc.to_string())
var xml_doc2 = new xml::document()
xml_doc2.parse(xml_doc.to_string())
xml.xml_check(xml_doc2.first_node().name() == "root")
xml.xml_check(xml_doc2.first_node().attributes().size() == 4)
xml.xml_check(xml_doc2.first_node().attributes("attr1").size() == 1)
xml.xml_check(xml_doc2.first_node().first_attribute().name() == "attr3")
xml.xml_check(xml_doc2.first_node().first_attribute().value() == "3")
xml.xml_check(xml_doc2.first_node().next_attribute(xml_doc2.first_node().first_attribute()).name() == "attr4")
xml.xml_check(xml_doc2.first_node().next_attribute(xml_doc2.first_node().first_attribute(), "attr1").name() == "attr1")
xml.xml_check(!xml_doc2.first_node().next_attribute(xml_doc2.first_node().first_attribute(), "attr3"))
xml.xml_check(xml_doc2.first_node().last_attribute().name() == "attr2")
xml.xml_check(xml_doc2.first_node().last_attribute().value() == "2")
xml.xml_check(xml_doc2.first_node().previous_attribute(xml_doc2.first_node().last_attribute()).name() == "attr1")
xml.xml_check(xml_doc2.first_node().previous_attribute(xml_doc2.first_node().last_attribute(), "attr4").name() == "attr4")
xml.xml_check(!xml_doc2.first_node().previous_attribute(xml_doc2.first_node().last_attribute(), "attr2"))
xml.xml_check(xml_doc2.first_node().first_attribute("attr1").value() == "1")
xml.xml_check(!xml_doc2.first_node().first_attribute("attr"))
xml.xml_check(xml_doc2.first_node().last_attribute("attr1").value() == "1")
xml.xml_check(!xml_doc2.first_node().last_attribute("attr"))
xml.xml_check(xml_doc2.first_node().children().size() == 2)
xml.xml_check(xml_doc2.first_node().first_node().name() == "roles")
xml.xml_check(xml_doc2.first_node().next_node(xml_doc2.first_node().first_node()).name() == "items")
xml.xml_check(!xml_doc2.first_node().next_node(xml_doc2.first_node().first_node(), "roles"))
xml.xml_check(!xml_doc2.first_node().first_node("none"))
xml.xml_check(xml_doc2.first_node().last_node().name() == "items")
xml.xml_check(xml_doc2.first_node().previous_node(xml_doc2.first_node().last_node()).name() == "roles")
xml.xml_check(!xml_doc2.first_node().previous_node(xml_doc2.first_node().last_node(), "items"))
xml.xml_check(!xml_doc2.first_node().last_node("none"))
xml.xml_check(xml_doc2.first_node().first_node("roles").name() == "roles")
xml.xml_check(xml_doc2.first_node().first_node("items").name() == "items")
xml.xml_check(xml_doc2.first_node().first_node().children().size() == 4)
xml.xml_check(xml_doc2.first_node().first_node().children("role").size() == 4)
xml.xml_check(xml_doc.to_string() == xml_doc2.to_string())
xml_doc2.first_node().remove_attribute(xml_doc2.first_node().first_attribute("attr1"))
xml.xml_check(xml_doc2.first_node().attributes().size() == 3)
xml_doc2.first_node().remove_first_attribute()
xml.xml_check(xml_doc2.first_node().attributes().size() == 2)
xml_doc2.first_node().remove_last_attribute()
xml.xml_check(xml_doc2.first_node().attributes().size() == 1)
var roles2 = xml_doc2.first_node().first_node()
xml.xml_check(roles2.children().size() == 4)
roles2.remove_node(roles2.first_node())
xml.xml_check(roles2.children().size() == 3)
roles2.remove_first_node()
xml.xml_check(roles2.children().size() == 2)
roles2.remove_last_node()
xml.xml_check(roles2.children().size() == 1)
xml_doc2.clear()
xml.xml_check(xml_doc2.to_string() == "\n")
// 会崩溃
// var xml_node = new xml::node("name", 0, "element");
// println(xml_node.type());
// println(xml_node.name());
// println(xml_node.value());