[gxml] Ported Python example to new API
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Ported Python example to new API
- Date: Wed, 6 Sep 2017 23:19:08 +0000 (UTC)
commit 0c6b68b49159fd5bd8f74fc4a9c4edd11469febd
Author: Daniel Espinosa <esodan gmail com>
Date: Wed Sep 6 13:19:59 2017 -0700
Ported Python example to new API
examples/python/example.py | 25 ++++++++++++++-----------
1 files changed, 14 insertions(+), 11 deletions(-)
---
diff --git a/examples/python/example.py b/examples/python/example.py
index a996a88..79afeb2 100755
--- a/examples/python/example.py
+++ b/examples/python/example.py
@@ -1,13 +1,15 @@
#!/usr/bin/python
from gi.repository import GXml;
+import gi
+gi.require_version('GXml', '0.16')
from gi.repository import Gio;
def create_a_document ():
authors = ["John Green", "Jane Austen", "J.D. Salinger"];
titles = ["The Fault in Our Stars", "Pride & Prejudice", "Nine Stories"];
- doc = GXml.Document.new ();
+ doc = GXml.GomDocument.new ();
root = doc.create_element ("Bookshelf");
doc.append_child (root);
root.set_attribute ("fullname", "John Green");
@@ -21,8 +23,8 @@ def create_a_document ():
book.set_attribute ("title", titles[i]);
books.append_child (book);
- print "create_a_document:\n", doc.to_string (True, 4);
- if None == doc.to_string (True, 4):
+ print "create_a_document:\n", doc.write_string()
+ if None == doc.write_string():
print "ERROR: doc to string was null, but shouldn't be";
def create_a_document_from_a_string ():
@@ -35,23 +37,24 @@ def create_a_document_from_a_string ():
<Book author="J.D. Salinger" title="Nine Stories"/>
</Books>
</Bookshelf>""";
- doc = GXml.Document.from_string (xml);
- print "create_a_document_from_a_string:\n", doc.to_string (True, 4);
+ doc = GXml.GomDocument.from_string (xml);
+ print "create_a_document_from_a_string:\n", doc.write_string ()
# TODO: why does this not indent when printed?
def create_a_document_from_a_file ():
can = Gio.Cancellable ();
gfile = Gio.File.new_for_path ("bookshelf.xml");
- doc = GXml.Document.from_gfile (gfile, can);
- print "create_a_document_from_a_file:\n", doc.to_string (True, 4); # TODO: do these two values actually
do anything?
+ doc = GXml.GomDocument.from_file (gfile);
+ print "create_a_document_from_a_file:\n", doc.write_string () # TODO: do these two values actually do
anything?
def create_a_document_from_a_path ():
- doc = GXml.Document.from_path ("bookshelf.xml");
- print "create_a_document_from_a_path:\n", doc.to_string (True, 4); # TODO: do these two values actually
do anything?
+ doc = GXml.GomDocument.from_path ("bookshelf.xml");
+ print "create_a_document_from_a_path:\n", doc.write_string () # TODO: do these two values actually do
anything?
def saving_a_document_to_a_path ():
- doc = GXml.Document.from_path ("bookshelf.xml");
- doc.save_to_path ("bookshelf2.xml");
+ f = Gio.File.new_for_path("bookshelf2.xml")
+ doc = GXml.GomDocument.from_path ("bookshelf.xml");
+ doc.write_file (f);
create_a_document ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]