|
1 import Qt 4.7 |
|
2 |
|
3 QtObject { |
|
4 property bool xmlTest: false |
|
5 property bool dataOK: false |
|
6 |
|
7 function checkElement(e, person, fruit) |
|
8 { |
|
9 if (e.tagName != "root") |
|
10 return; |
|
11 |
|
12 if (e.nodeName != "root") |
|
13 return; |
|
14 |
|
15 if (e.nodeValue != null) |
|
16 return; |
|
17 |
|
18 if (e.nodeType != 1) |
|
19 return; |
|
20 |
|
21 var childTagNames = [ "person", "fruit" ]; |
|
22 |
|
23 if (e.childNodes.length != childTagNames.length) |
|
24 return; |
|
25 |
|
26 for (var ii = 0; ii < childTagNames.length; ++ii) { |
|
27 if (e.childNodes[ii].tagName != childTagNames[ii]) |
|
28 return; |
|
29 } |
|
30 |
|
31 if (e.childNodes[childTagNames.length + 1] != null) |
|
32 return; |
|
33 |
|
34 // Check writing fails |
|
35 e.childNodes[0] = null; |
|
36 if (e.childNodes[0] == null) |
|
37 return; |
|
38 |
|
39 e.childNodes[10] = 10; |
|
40 if (e.childNodes[10] != null) |
|
41 return; |
|
42 |
|
43 if (e.firstChild.tagName != e.childNodes[0].tagName) |
|
44 return; |
|
45 |
|
46 if (e.lastChild.tagName != e.childNodes[1].tagName) |
|
47 return; |
|
48 |
|
49 if (e.previousSibling != null) |
|
50 return; |
|
51 |
|
52 if (e.nextSibling != null) |
|
53 return; |
|
54 |
|
55 if (e.attributes == null) |
|
56 return; |
|
57 |
|
58 if (e.attributes.length != 2) |
|
59 return; |
|
60 |
|
61 var attr1 = e.attributes["attr"]; |
|
62 if (attr1.nodeValue != "value") |
|
63 return; |
|
64 |
|
65 var attrIdx = e.attributes[0]; |
|
66 if (attrIdx.nodeValue != "value") |
|
67 return; |
|
68 |
|
69 var attr2 = e.attributes["attr2"]; |
|
70 if (attr2.nodeValue != "value2") |
|
71 return; |
|
72 |
|
73 var attr3 = e.attributes["attr3"]; |
|
74 if (attr3 != null) |
|
75 return; |
|
76 |
|
77 var attrIdx2 = e.attributes[11]; |
|
78 if (attrIdx2 != null) |
|
79 return; |
|
80 |
|
81 // Check writing fails |
|
82 e.attributes[0] = null; |
|
83 if (e.attributes[0] == null) |
|
84 return; |
|
85 |
|
86 e.attributes["attr"] = null; |
|
87 if (e.attributes["attr"] == null) |
|
88 return; |
|
89 |
|
90 e.attributes["attr3"] = 10; |
|
91 if (e.attributes["attr3"] != null) |
|
92 return; |
|
93 |
|
94 // Check person and fruit sub elements |
|
95 if (person.parentNode.nodeName != "root") |
|
96 return; |
|
97 |
|
98 if (person.previousSibling != null) |
|
99 return; |
|
100 |
|
101 if (person.nextSibling.nodeName != "fruit") |
|
102 return; |
|
103 |
|
104 if (fruit.parentNode.nodeName != "root") |
|
105 return; |
|
106 |
|
107 if (fruit.previousSibling.nodeName != "person") |
|
108 return; |
|
109 |
|
110 if (fruit.nextSibling != null) |
|
111 return; |
|
112 |
|
113 xmlTest = true; |
|
114 } |
|
115 |
|
116 function checkXML(document) |
|
117 { |
|
118 checkElement(document.documentElement, |
|
119 document.documentElement.childNodes[0], |
|
120 document.documentElement.childNodes[1]); |
|
121 } |
|
122 |
|
123 Component.onCompleted: { |
|
124 var x = new XMLHttpRequest; |
|
125 |
|
126 x.open("GET", "element.xml"); |
|
127 |
|
128 // Test to the end |
|
129 x.onreadystatechange = function() { |
|
130 if (x.readyState == XMLHttpRequest.DONE) { |
|
131 |
|
132 dataOK = true; |
|
133 |
|
134 if (x.responseXML != null) |
|
135 checkXML(x.responseXML); |
|
136 |
|
137 } |
|
138 } |
|
139 |
|
140 x.send() |
|
141 } |
|
142 } |
|
143 |
|
144 |
|
145 |