File: document_new.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 (34 lines) | stat: -rwxr-xr-x 1,027 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
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/gjs

const GXml = imports.gi.GXml;
const Gio = imports.gi.Gio;

function create_a_document () {
    var authors = [ "John Green", "Jane Austen", "J.D. Salinger" ];
    var titles = [ "The Fault in Our Stars", "Pride & Prejudice", "Nine Stories" ];

    try {
        let doc = GXml.GomDocument.new ();
        let root = doc.create_element ("Bookshelf");
        doc.append_child (root);
        let owner = doc.create_element ("Owner");
        root.append_child (owner);
        owner.set_attribute ("fullname", "John Green");

        let books = doc.create_element ("Books");
        root.append_child (books);

        for (var i = 0; i < authors.get_length (); i++) {
            let book = doc.create_element ("Book");
            book.set_attribute ("author", authors[i]);
            book.set_attribute ("title", titles[i]);
            books.append_child (book);
        }

	print ("create_a_document:\n" + doc.write_string ());
    } catch (error) {
	print (error.message);
    }
}

create_a_document ();