File: node_list.js

package info (click to toggle)
gxml 0.20.4%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,364 kB
  • sloc: xml: 131,277; ansic: 786; javascript: 328; python: 88; makefile: 35; sh: 11
file content (23 lines) | stat: -rwxr-xr-x 719 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/gjs

const GXml = imports.gi.GXml;

/* For more examples, view node's child management code */

// Setup
var doc = GXml.GomDocument.from_string ("<Refrigerator><Food name='cheese' /><Food name='tomatoes' /><Food name='avocado' /></Refrigerator>");

var foods_list = doc.get_elements_by_tag_name ("Food");


print ("Our refrigerator:\n" + doc.write_string ());

print ("\nThe length of the list:  " + foods_list.get_length ()+"\n");

print ("\nAccessing the second food item from a nodelist using .item ():\n  " +
       foods_list.item (1).get_attribute ('name'));

for (var i = 0; i < foods_list.get_length (); i++) {
    var food = foods_list.item (i);
    print ("  " + i + ":" + food.write_string ());
}