[gxml.wiki] Update element adding examples to map XML to GObject



commit fc37478326091886724b6fccf022c4c7c157cec7
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date:   Fri Feb 28 00:35:32 2020 +0000

    Update element adding examples to map XML to GObject

 element.md    | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 gomelement.md | 13 -------------
 2 files changed, 49 insertions(+), 13 deletions(-)
---
diff --git a/element.md b/element.md
new file mode 100644
index 0000000..53848b7
--- /dev/null
+++ b/element.md
@@ -0,0 +1,49 @@
+# Introduction
+
+`GXml.Element` is a class implementing `GXml.DomElement` and so DOM4 API. It represent an XML element node 
with attributes and child nodes.
+
+For GXml's serialization is the current maintained implementation, with fast parsing and writing 
capabilities and small footprint.
+
+You can use [Collections](collections) to access child nodes in a very easy and straightforward way.
+
+# Data Model
+
+In `GXml.Element` data model, an XML element node is mapped to a `GObject` class and its attributes are 
mapped to `GObject`'s properties if they are basic types or a `GXml.Property` implementation classes.
+
+All `Element`derived classes provides a DOM4 API and allows to add any `DomNode` implementation class (just 
restricted to be derived from `GXml.Node`). It is possible to set any attribute, add text nodes or any other 
`GXml.DomElement`. Read an XML tree with any content is possible from a `GXml.Element` object, just 
restricted to the first element to read should have use a node's name compatible with the one defined at 
construction time of the class.
+
+## Examples
+
+```c++
+// A `<Name/>` element definition
+class Name : GXml.Element
+{
+  // Here you set the name of the node, so is possible to use any name or case
+  construct { try { initialize ("Name"); } catch { assert_not_reached (); } }
+}
+
+class Email : GXml.Element
+{
+  construct {  try { initialize ("Email"); } catch { assert_not_reached (); } }
+}
+
+// This is the parent element for <Name/> and <Email/> nodes
+class Author : GXml.Element
+{
+  // Here the parser will use the first <Name/> node to set this property
+  public Name name { get; set; }
+  // Here the parser will use the first <Email/> node to set this property
+  public Email email { get; set; }
+  // Here is the <Autor/> node name initialization
+  construct { try { initialize ("Author"); } catch { assert_not_reached (); } }
+}
+```
+
+The result is that, the following XML content will be mapped to a `Author` class setting its properties, 
just using `read_from_string()` method.
+
+```xml
+<Author>
+   <Name>Jhon Ethernet</Name>
+   <Email>je gnome org</Email>
+</Author>
+```
\ No newline at end of file


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]