GXmlGomObject

GXmlGomObject — A GXml Object Model (GOM) represents a GXmlDomElement. It has attributes and children. All object's properties are handled as attributes if they are basic types like integers, strings, enums and others; GXmlSerializableProperty objects are handled as attributes too. If object's attribute is a GObject it is handled as node's child, but only if it is a GXmlGomElement object, other wise it is ignored when this object is used as GXmlDomNode in XML documents.

Functions

Types and Values

Description

Functions

gxml_gom_object_get_properties_list ()

GList *
gxml_gom_object_get_properties_list (GXmlGomObject *self);

Returns a list with all properties' nick with "::" prefix. Nick name, with "::" prefix will be used on serialization to an attribute's name.

Parameters

self

the GXmlGomObject instance

 

gxml_gom_object_find_property_name ()

GParamSpec *
gxml_gom_object_find_property_name (GXmlGomObject *self,
                                    const gchar *pname);

Returns property's GParamSpec based on given nick. This function is case insensitive.

Parameters

self

the GXmlGomObject instance

 

pname

 

 

gxml_gom_object_find_object_property_name ()

GParamSpec *
gxml_gom_object_find_object_property_name
                               (GXmlGomObject *self,
                                const gchar *pname);

Returns a GXmlGomObject or a GXmlGomCollection property's GParamSpec based on given name. This method is case insensitive.

This method will check if nick's name is equal than given name in order to avoid use canonical names like "your-name" if your property is your_name; so you can se nick to "YourName" to find and instantiate it.

Parameters

self

the GXmlGomObject instance

 

pname

 

 

gxml_gom_object_get_property_element_list ()

GList *
gxml_gom_object_get_property_element_list
                               (GXmlGomObject *self);

Returns a list of names for all GXmlDomElement present as object's properties.

Parameters

self

the GXmlGomObject instance

 

gxml_gom_object_get_property_string ()

gchar *
gxml_gom_object_get_property_string (GXmlGomObject *self,
                                     GParamSpec *prop);

Returns an string representation of an Object's property.

Parameters

self

the GXmlGomObject instance

 

prop

 

 

gxml_gom_object_get_attribute ()

gchar *
gxml_gom_object_get_attribute (GXmlGomObject *self,
                               const gchar *name);

Search for properties in objects, it should be an GObject's property. If found a property with given name its value is returned as string representation.

If property is a GXmlGomProperty returned value is a string representation according with object implementation.

If given property name is not found, then gxml_dom_element_get_attribute() is called.

By default all GObject are children of this object, see gxml_gom_object_get_child()

Parameters

self

the GXmlGomObject instance

 

name

 

 

gxml_gom_object_set_attribute ()

gboolean
gxml_gom_object_set_attribute (GXmlGomObject *self,
                               const gchar *name,
                               const gchar *val);

Search for a GObject property with given name, if found, given string representation is used as value to property, using any required transformation from string.

By default all GObject are children of this object.

Parameters

self

the GXmlGomObject instance

 

name

 

 

val

 

 

gxml_gom_object_get_child ()

GXmlDomElement *
gxml_gom_object_get_child (GXmlGomObject *self,
                           const gchar *name);

Search a GObject property with given name and returns it, if it is a GXmlDomElement. If not found, gxml_dom_element_get_elements_by_tag_name() is called, returning first node found. Tag name to use, is the given name parameter.

Parameters

self

the GXmlGomObject instance

 

name

 .

a name of this object's property of type GXmlDomElement or first GXmlDomNode with that name in child nodes.

.

[in]

gxml_gom_object_find_elements ()

GXmlDomElementList *
gxml_gom_object_find_elements (GXmlGomObject *self,
                               const gchar *name);

From a given property name of type GXmlGomElement, search all child nodes with node's local name equal to property.

Parameters

self

the GXmlGomObject instance

 

name

 

 

gxml_gom_object_remove_attribute ()

gboolean
gxml_gom_object_remove_attribute (GXmlGomObject *self,
                                  const gchar *name);

Search for a property and set it to null if possible returning true, if value can't be removed or located, returns false without change.

Parameters

self

the GXmlGomObject instance

 

name

 

 

gxml_gom_object_set_instance_property ()

gboolean
gxml_gom_object_set_instance_property (GXmlGomObject *self,
                                       const gchar *name);

Convenient method to set an instance of given property's name and initialize according to have same "owner-document" and set its "parent-node" to this appending it as a child. If property is a GXmlGomCollection it is initialize to use this as its "element".

Instance is set ot object's property.

Property should be a GXmlGomElement or GXmlGomCollection

While an object could be created and set to a Object's property, it is not correctly initialized by default. This method helps in the process.

If Object's property has been set, this method overwrite it.

1
2
3
4
5
6
7
8
9
10
class NodeA : GomObject {
  construct { try { initialize ("NodeA"); } catch { warning ("Can't initialize); }
}
class NodeB : GomObject {
  public NodeA node { get; set; }
}

var nb = new NodeB ();
nb.create_instance_property ("node");
assert (nb.node != null);

Returns: true if property has been set and initialized, false otherwise.

Parameters

self

the GXmlGomObject instance

 

name

 

 

gxml_gom_object_clean_property_elements ()

void
gxml_gom_object_clean_property_elements
                               (GXmlGomObject *self,
                                const gchar *name,
                                GError **error);

Utility method to remove all instances of a property being child elements of object. Is useful if you have a GXmlGomElement property, it should be just one child of this type and you want to overwrite it.

In this example you have defined an element MyClass to be child of MyParentClass, but it should have just one element, once you set child_elements it calls gxml_gom_object_clean_property_elements() using property's canonicals name.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class MyClass : GomElement {
  public string name { get; set; }
}
public class MyParentClass : GomElement {
  private Myclass _child_elements = null;
  public MyClass child_elements {
    get { return _child_elements; }
    set {
      try {
        clean_property_elements ("child-elements");
        _child_elements = value;
        append_child (_child_elements);
      } catch (GLib.Error e) {
        warning (e.message);
      }
    }
  }
}

GXmlDomError will be returned in error

if property is not a GXmlGomElement.

Parameters

self

the GXmlGomObject instance

 

name

 .

property name to search value type, use canonical names.

.

[in]

error

location to store the error occuring, or NULL to ignore

 

Types and Values

GXmlGomObject

typedef struct _GXmlGomObject GXmlGomObject;

A GXml Object Model (GOM) represents a GXmlDomElement. It has attributes and children. All object's properties are handled as attributes if they are basic types like integers, strings, enums and others; GXmlSerializableProperty objects are handled as attributes too. If object's attribute is a GObject it is handled as node's child, but only if it is a GXmlGomElement object, other wise it is ignored when this object is used as GXmlDomNode in XML documents.


struct GXmlGomObjectIface

struct GXmlGomObjectIface {
	GTypeInterface parent_iface;
	GList* (*get_properties_list) (GXmlGomObject* self);
	GParamSpec* (*find_property_name) (GXmlGomObject* self, const gchar* pname);
	GParamSpec* (*find_object_property_name) (GXmlGomObject* self, const gchar* pname);
	GList* (*get_property_element_list) (GXmlGomObject* self);
	gchar* (*get_property_string) (GXmlGomObject* self, GParamSpec* prop);
	gchar* (*get_attribute) (GXmlGomObject* self, const gchar* name);
	gboolean (*set_attribute) (GXmlGomObject* self, const gchar* name, const gchar* val);
	GXmlDomElement* (*get_child) (GXmlGomObject* self, const gchar* name);
	GXmlDomElementList* (*find_elements) (GXmlGomObject* self, const gchar* name);
	gboolean (*remove_attribute) (GXmlGomObject* self, const gchar* name);
	gboolean (*set_instance_property) (GXmlGomObject* self, const gchar* name);
	void (*clean_property_elements) (GXmlGomObject* self, const gchar* name, GError** error);
};

Interface for creating GXmlGomObject implementations.

Members

GTypeInterface parent_iface;

the parent interface structure

 

get_properties_list ()

virtual method called by gxml_gom_object_get_properties_list()

 

find_property_name ()

virtual method called by gxml_gom_object_find_property_name()

 

find_object_property_name ()

virtual method called by gxml_gom_object_find_object_property_name()

 

get_property_element_list ()

virtual method called by gxml_gom_object_get_property_element_list()

 

get_property_string ()

virtual method called by gxml_gom_object_get_property_string()

 

get_attribute ()

virtual method called by gxml_gom_object_get_attribute()

 

set_attribute ()

virtual method called by gxml_gom_object_set_attribute()

 

get_child ()

virtual method called by gxml_gom_object_get_child()

 

find_elements ()

virtual method called by gxml_gom_object_find_elements()

 

remove_attribute ()

virtual method called by gxml_gom_object_remove_attribute()

 

set_instance_property ()

virtual method called by gxml_gom_object_set_instance_property()

 

clean_property_elements ()

virtual method called by gxml_gom_object_clean_property_elements()