File: text.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 (36 lines) | stat: -rwxr-xr-x 1,214 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
35
36
#!/usr/bin/gjs

const GXml = imports.gi.GXml;

// Setup
var doc = GXml.GomDocument.new ();
doc.append_child (doc.create_element ("Diary"));

var text = doc.create_text_node ("I am the very model of a modern Major General.");

print ("Document before inserting text:\n" +
       doc.write_string ());

doc.document_element.append_child (text);

print ("Document after inserting text:\n" +
       doc.write_string ());

print ("Nodes of document element 'Diary' before split_text:");
for (var node = doc.document_element.first_child; node != null; node = node.next_sibling) {
    print ("  Node: " + node.get_node_name()+":"+node.get_node_value ());
}

text.split_text (20);

print ("\nNodes of document element 'Diary' after split_text:");
for (var node = doc.document_element.first_child; node != null; node = node.next_sibling) {
    print ("  Node: " + node.get_node_name()+":"+node.get_node_value ());
}

print ("\nWARNING: the above does not work as desired, since libxml2 automatically merges neighbouring Text nodes.  You should see two Nodes for each part of the split.  This will hopefully be addressed in the future.");

/* To see Text manipulated as CharacterData, go see the CharacterData example */