| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
gTestfile = '12.2.js'; |
| 8 |
|
| 9 |
START("12.2 - For-in statement"); |
| 10 |
|
| 11 |
|
| 12 |
e = |
| 13 |
<employees> |
| 14 |
<employee id="1"> |
| 15 |
<name>Joe</name> |
| 16 |
<age>20</age> |
| 17 |
</employee> |
| 18 |
<employee id="2"> |
| 19 |
<name>Sue</name> |
| 20 |
<age>30</age> |
| 21 |
</employee> |
| 22 |
</employees>; |
| 23 |
|
| 24 |
correct = new Array("Joe", "Sue", "Big Screen Television", "1299.99"); |
| 25 |
|
| 26 |
i = 0; |
| 27 |
for (var n in e..name) |
| 28 |
{ |
| 29 |
TEST("1."+i, String(i), n); |
| 30 |
i++; |
| 31 |
} |
| 32 |
TEST("1.count", 2, i); |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
order = |
| 37 |
<order> |
| 38 |
<customer> |
| 39 |
<name>John Smith</name> |
| 40 |
</customer> |
| 41 |
<item id="1"> |
| 42 |
<description>Big Screen Television</description> |
| 43 |
<price>1299.99</price> |
| 44 |
</item> |
| 45 |
<item id="2"> |
| 46 |
<description>DVD Player</description> |
| 47 |
<price>399.99</price> |
| 48 |
</item> |
| 49 |
</order>; |
| 50 |
|
| 51 |
i = 0; |
| 52 |
for (var child in order.item) |
| 53 |
{ |
| 54 |
TEST("2."+i, String(i), child); |
| 55 |
i++ |
| 56 |
} |
| 57 |
TEST("2.count", 2, i); |
| 58 |
|
| 59 |
i = 0; |
| 60 |
for (var child in order.item[0].*) |
| 61 |
{ |
| 62 |
TEST("3."+i, String(i), child); |
| 63 |
i++ |
| 64 |
} |
| 65 |
|
| 66 |
TEST("3.count", 2, i); |
| 67 |
|
| 68 |
END(); |