[gxml] GOM: Fixing more build errors
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] GOM: Fixing more build errors
- Date: Thu, 27 Oct 2016 20:12:25 +0000 (UTC)
commit 018b88d26efe8f899fa628464db4f8fd97145384
Author: Daniel Espinosa <esodan gmail com>
Date: Thu Oct 27 13:34:22 2016 -0500
GOM: Fixing more build errors
gxml/DomNode.vala | 18 +++--
gxml/GomAttr.vala | 61 +++++++++++++++
gxml/GomElement.vala | 208 +++++++++++++++++++++++++++++---------------------
gxml/GomNode.vala | 100 +++++++-----------------
gxml/GomObject.vala | 33 ++++++---
gxml/Makefile.am | 1 +
6 files changed, 248 insertions(+), 173 deletions(-)
---
diff --git a/gxml/DomNode.vala b/gxml/DomNode.vala
index 7021655..b16f307 100644
--- a/gxml/DomNode.vala
+++ b/gxml/DomNode.vala
@@ -81,17 +81,17 @@ public interface GXml.DomNode : GLib.Object, GXml.DomEventTarget {
public abstract DomNode remove_child (DomNode child) throws GLib.Error;
public virtual DomNode clone_node (bool deep = false) {
DomNode n = new GomNode ();
- if (_document == null) return new GomNode ();
+ if (owner_document == null) return new GomNode ();
switch (node_type) {
case NodeType.ELEMENT_NODE:
- n = _document.create_element (node_name);
- copy (_document, n, this, true);
+ n = owner_document.create_element (node_name);
+ copy (owner_document, n, this, true);
break;
case NodeType.COMMENT_NODE:
- n = _document.create_comment ((this as DomComment).data);
+ n = owner_document.create_comment ((this as DomComment).data);
break;
case NodeType.TEXT_NODE:
- n = _document.create_text_node ((this as DomText).data);
+ n = owner_document.create_text_node ((this as DomText).data);
break;// FIXME: more nodes
}
return n;
@@ -144,8 +144,12 @@ public interface GXml.DomNode : GLib.Object, GXml.DomEventTarget {
GLib.warning (_("Text node with NULL string"));
continue;
}
- var t = doc.create_text_node ((c as DomText).data);
- node.child_nodes.add (t);
+ try {
+ var t = doc.create_text_node ((c as DomText).data);
+ node.child_nodes.add (t);
+ } catch (GLib.Error e) {
+ GLib.warning (_("Can't copy child text node"));
+ }
#if DEBUG
GLib.message (@"Copying source's Text node '$(source.node_name)' to destiny node with text:
$(c.node_value) : Size= $(node.child_nodes.size)");
GLib.message (@"Added Text: $(node.child_nodes.get (node.child_nodes.size - 1))");
diff --git a/gxml/GomAttr.vala b/gxml/GomAttr.vala
new file mode 100644
index 0000000..419a34a
--- /dev/null
+++ b/gxml/GomAttr.vala
@@ -0,0 +1,61 @@
+/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
+/*
+ *
+ * Copyright (C) 2016 Daniel Espinosa <esodan gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Daniel Espinosa <esodan gmail com>
+ */
+
+using GXml;
+using Gee;
+
+
+public class GXml.GomAttr : GXml.GomNode {
+ protected string _namespace_uri;
+ protected string _prefix;
+ public string local_name { owned get { return _local_name; } }
+ public string name {
+ owned get {
+ string s = "";
+ if (_prefix != null) s = _prefix+":";
+ return s+_local_name;
+ }
+ }
+ public string? namespace_uri { owned get { return _namespace_uri; } }
+ public string? prefix {
+ owned get {
+ if (_prefix == "") return null;
+ return _prefix;
+ }
+ }
+ public string value { owned get { return _node_value; } set { _node_value = value; } }
+
+ public GomAttr (DomElement element, string name, string value) {
+ _document = element.owner_document;
+ _parent = element;
+ _local_name = name;
+ _node_value = value;
+ }
+ public GomAttr.namespace (DomElement element, string namespace_uri, string? prefix, string name, string
value) {
+ _document = element.owner_document;
+ _parent = element;
+ _local_name = name;
+ _node_value = value;
+ _namespace_uri = namespace_uri;
+ _prefix = prefix;
+ }
+}
diff --git a/gxml/GomElement.vala b/gxml/GomElement.vala
index 8bbce8f..e2d0d23 100644
--- a/gxml/GomElement.vala
+++ b/gxml/GomElement.vala
@@ -27,31 +27,49 @@ using Gee;
* transparently as {@link DomElement} in a XML tree.
*/
public class GXml.GomElement : GomNode,
- DomChildNode,
- DomNonDocumentTypeChildNode,
- DomParentNode,
- DomElement,
- GomObject {
- /**
- * Holds namespaces in current node, using URI as key and prefix as value
- */
- protected Gee.HashMap<string?,string> _namespaces = new Gee.HashMap<string?,string> ();
-
-
+ DomNode,
+ DomChildNode,
+ DomNonDocumentTypeChildNode,
+ DomParentNode,
+ DomElement,
+ GomObject {
// DomNode overrides
public string? lookup_prefix (string? nspace) {
- if (nspace == null) return null;
- var nsp = _namespaces.get (nspace);
- if (nsp == "") return null;
- return nsp;
+ if (namespace_uri == nspace && this.prefix != null)
+ return this.prefix;
+ foreach (DomNode a in attributes.values) {
+ if ((a as DomAttr).prefix == null) continue;
+ if ((a as DomAttr).prefix.down () == "xmlns" && a.node_value == nspace)
+ return (a as DomAttr).local_name;
+ }
+ if (parent_node == null) return null;
+ return parent_node.lookup_prefix (nspace);
}
- public string? lookup_namespace_uri (string? prefix) {
+ public string? DomNode.lookup_namespace_uri (string? prefix) {
+ if (namespace_uri != null && this.prefix == prefix)
+ return namespace_uri;
string s = "";
if (prefix != null) s = prefix;
- foreach (string k in _namespaces.keys) {
- if (_namespaces.get (k) == prefix) return k;
+ foreach (DomNode a in attributes.values) {
+ if ((a as DomAttr).namespace_uri == "http://www.w3.org/2000/xmlns/")
+ if ((a as DomAttr).prefix != null)
+ if ((a as DomAttr).prefix.down () == "xmlns"
+ && (a as DomAttr).local_name == s)
+ if (a.node_value == "")
+ return null;
+ else
+ return a.node_value;
+ if ((a as DomAttr).prefix == null
+ && s == ""
+ && (a as DomAttr).local_name == "xmlns"
+ && (a as DomAttr).namespace_uri == "http://www.w3.org/2000/xmlns/")
+ if (a.node_value == "")
+ return null;
+ else
+ return a.node_value;
}
- return null;
+ if (parent_node == null) return null;
+ return parent_node.lookup_namespace_uri (prefix);
}
// DomChildNode
@@ -143,6 +161,7 @@ public class GXml.GomElement : GomNode,
construct {
_node_type = DomNode.NodeType.ELEMENT_NODE;
+ _attributes = new Attributes (this);
}
public GomElement (DomDocument doc, string local_name) {
@@ -153,98 +172,105 @@ public class GXml.GomElement : GomNode,
_document = doc;
_local_name = local_name;
_namespace_uri = namespace;
- string nsp = prefix;
- if (nsp == null) nsp = "";
- _prefix = nsp;
- if (!_namespaces.has_key (namespace))
- _namespaces.set (namespace, nsp);
+ _prefix = prefix;
}
/**
* Holds attributes in current node, using attribute's name as key
* and it's value as value. Appends namespace prefix to attribute's name as
* key if a namespaced attribute.
*/
- protected class Attributes : HashMap<string,string>, DomNamedNodeMap {
+ public class Attributes : HashMap<string,string>, DomNamedNodeMap {
+ protected GomElement _element;
public ulong length { get { return (ulong) size; } }
public DomNode? item (ulong index) { return null; }
+
+ public Attributes (GomElement element) {
+ _element = element;
+ }
+
public DomNode? get_named_item (string name) {
+ // TODO: Validate name throw INVALID_CHARACTER_ERROR
+ if (name == "") return null;
if (":" in name) return null;
var v = get (name);
if (v == null) return null;
- var n = new GomAttr (this, name, v);
+ var n = new GomAttr (_element, name, v);
return n;
}
+ /**
+ * Takes given {@link DomNode} as a {@link DomAttr} and use its name and
+ * value to set a property in {@link DomElement} ignoring node's prefix and
+ * namespace
+ */
public DomNode? set_named_item (DomNode node) throws GLib.Error {
- if (":" in node.node_name) return null;
+ if ((":" in node.node_name)
+ || node.node_name == "")
+ throw new DomError.INVALID_CHARACTER_ERROR (_("Invalid attribute name"));
+ if (!(node is DomAttr))
+ throw new DomError.HIERARCHY_REQUEST_ERROR (_("Invalid node type. DomAttr was expected"));
set (node.node_name, node.node_value);
- var n = new GomAttr (this, node.node_name, node.node_value);
+ return new GomAttr (_element, node.node_name, node.node_value);
}
public DomNode? remove_named_item (string name) throws GLib.Error {
if (":" in name) return null;
var v = get (name);
if (v == null) return null;
- var n = new GomAttr (this, name, v);
+ var n = new GomAttr (_element, name, v);
set (name, null);
return n;
}
// Introduced in DOM Level 2:
public DomNode? remove_named_item_ns (string namespace_uri, string local_name) throws GLib.Error {
if (":" in local_name) return null;
- var nsp = _name_spaces.get (namespace_uri);
- if (nsp == null) return null;
+ var nsp = _element.lookup_prefix (namespace_uri);
+ if (nsp == null || nsp == "") return null;
var v = get (nsp+":"+local_name);
if (v == null) return null;
- var n = new GomAttr (this, namespace_uri, nsp, local_name, v);
- set (name, null);
+ var n = new GomAttr.namespace (_element, namespace_uri, nsp, local_name, v);
+ unset (nsp+":"+local_name);
return n;
}
// Introduced in DOM Level 2:
public DomNode? get_named_item_ns (string namespace_uri, string local_name) throws GLib.Error {
if (":" in local_name) return null;
- var nsp = _name_spaces.get (namespace_uri);
+ var nsp = _element.lookup_prefix (namespace_uri);
if (nsp == null) return null;
var v = get (nsp+":"+local_name);
if (v == null) return null;
- var n = new GomNode ();
- n._node_value = v;
- n._local_name = local_name;
+ var n = new GomAttr.namespace (_element, namespace_uri, nsp, local_name, v);
return n;
}
// Introduced in DOM Level 2:
public DomNode? set_named_item_ns (DomNode node) throws GLib.Error {
- /* TODO:Ç
- WRONG_DOCUMENT_ERR: Raised if arg was created from a different document than the one that created this
map.
-
-NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
-
-INUSE_ATTRIBUTE_ERR: Raised if arg is an Attr that is already an attribute of another Element object. The
DOM user must explicitly clone Attr nodes to re-use them in other elements.
-
-HIERARCHY_REQUEST_ERR: Raised if an attempt is made to add a node doesn't belong in this NamedNodeMap.
Examples would include trying to insert something other than an Attr node into an Element's map of
attributes, or a non-Entity node into the DocumentType's map of Entities.
-
-NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feature "XML" and the language
exposed through the Document does not support XML Namespaces (such as [HTML 4.01]).
- */
- string ns, ln, nsp;
- if (node is DomElement) {
- ns = (node as DomElement).namespace_uri;
- ln = (node as DomElement).local_name;
- nsp = (node as DomElement).prefix;
- } else
- return null;
- if (":" in ln)
- throw new DomError.NOT_SUPPORTED_ERROR (_("Invalid local name"));
- var nsp = _name_spaces.get (ns);
- if (nsp == null && _namespaces.size == 0) {
- _namespaces.set (ns, "");
+ if (node.node_name == "")
+ throw new DomError.INVALID_CHARACTER_ERROR (_("Invalid attribute name"));
+ if (!(node is DomAttr))
+ throw new DomError.HIERARCHY_REQUEST_ERROR (_("Invalid node type. DomAttr was expected"));
+ string n = (node as DomAttr).local_name;
+ string ns = (node as DomAttr).namespace_uri;
+ string v = node.node_value;
+ if ((node as DomAttr).prefix == null
+ && (node as DomAttr).local_name.down () != "xmlns") {
+ set ("xmlns","http://www.w3.org/2000/xmlns/");
+ return new GomAttr (_element, "xmlns", "http://www.w3.org/2000/xmlns/");
}
- if (nsp == null) nsp = "";
- set (nsp+":"+local_name, node.node_value);
- var n = new GomNode ();
- n.node_value = v;
- n._local_name = name;
- return n;
+ if ((node as DomAttr).prefix == null
+ || (node as DomAttr).prefix == "") {
+ set ((node as DomAttr).local_name, node.node_value);
+ return new GomAttr (_element, node.node_name, node.node_value);
+ }
+ string p = null;
+ if ((node as DomAttr).prefix != ""
+ && (node as DomAttr).prefix != null) p = (node as DomAttr).prefix;
+ set (p+":"+(node as DomAttr).local_name, node.node_value);
+ if ((node as DomAttr).prefix.down () == "xmlns"
+ || (node as DomAttr).local_name == "xmlns")
+ ns = node.node_value;
+ return new GomAttr.namespace (_element,
+ ns, p, n, node.node_value);
}
}
- protected Attributes _attributes = new Attributes ();
+ protected Attributes _attributes;
public DomNamedNodeMap attributes { owned get { return (DomNamedNodeMap) _attributes; } }
public string? get_attribute (string name) { return (this as GomObject).get_attribute (name); }
public string? get_attribute_ns (string? namespace, string local_name) {
@@ -258,8 +284,11 @@ NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feat
if (p == null) return null;
return p.node_value;
}
- public void set_attribute (string name, string? value) { (this as GomObject).set_attribute (name, value); }
- public void set_attribute_ns (string? namespace, string name, string? value) {
+ public void set_attribute (string name, string? value) {
+ var a = new GomAttr (this, name, value);
+ attributes.set_named_item (a);
+ }
+ public void set_attribute_ns (string? namespace_uri, string name, string? value) {
string p = "";
string n = name;
if (":" in name) {
@@ -269,32 +298,39 @@ NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feat
n = s[1];
} else
n = name;
- //TODO: Throw errors on xmlns and no MXLNS https://www.w3.org/TR/dom/#dom-element-setattributens
- var nsp = _namespaces.get (namespace);
- if (nsp != p) {
- _namespaces.set (namespace, p); // Set Default
+ if (p == "xml" && namespace_uri != "http://www.w3.org/2000/xmlns/") {
+ GLib.warning (_("Invalid namespace. If prefix is xml name space uri shoud be
http://www.w3.org/2000/xmlns/"));
+ return;
}
- _attributes.set (p+":"+n, value);
+ if (p == "xmlns" && namespace_uri != "http://www.w3.org/2000/xmlns/") {
+ GLib.warning (_("Invalid namespace. If attribute's name is xmlns name space uri shoud be
http://www.w3.org/2000/xmlns/"));
+ return;
+ }
+ // Check a namespace is set
+ if (_prefix == null && _namespace_uri == null)
+ if (p.down () == "xmlns"
+ || n == "xmlns")
+ {
+ if (p != "")
+ _prefix = p;
+ _namespace_uri = namespace_uri;
+ }
+ var a = new GomAttr.namespace (this, namespace_uri, p, n, value);
+ _attributes.set_named_item_ns (a);
}
public void remove_attribute (string name) {
(this as GomElement).remove_attribute (name);
}
- public void remove_attribute_ns (string? namespace, string local_name) {
- if (":" in local_name) return;
- var nsp = _namespaces.get (namespace);
- if (nsp == null) return;
- var a = _attributes.get (nsp+local_name);
- if (a == null) return;
- _namespaces.set (nsp+local_name, null);
+ public void remove_attribute_ns (string? namespace_uri, string local_name) {
+ attributes.remove_named_item_ns (namespace_uri, local_name);
}
public bool has_attribute (string name) {
return _attributes.has_key (name);
}
- public bool has_attribute_ns (string? namespace, string local_name) {
- var nsp = _namespaces.get (namespace);
- if (nsp == null) return false;
- var a = _namespaces.get (nsp+local_name);
- if (a != null) return true;
+ public bool has_attribute_ns (string? namespace_uri, string local_name) {
+ var p = lookup_prefix (namespace_uri);
+ if (p == null) return false;
+ return attributes.has_key (p+":"+local_name);
}
diff --git a/gxml/GomNode.vala b/gxml/GomNode.vala
index 3a3999f..85a57dd 100644
--- a/gxml/GomNode.vala
+++ b/gxml/GomNode.vala
@@ -52,7 +52,7 @@ public class GXml.GomNode : Object,
return null;
}
}
-
+ // TODO: Move to GomElement
protected class NodeList : Gee.ArrayList<DomNode>, DomNodeList {
public DomNode? item (ulong index) { return base.get ((int) index); }
public ulong length { get { return (ulong) base.size; } }
@@ -73,24 +73,26 @@ public class GXml.GomNode : Object,
}
public DomNode? previous_sibling {
owned get {
- if (_parent == null) return null;
- if (_parent.child_nodes == null) return null;
- if (_parent.child_nodes.length == 0) return null;
- var pos = (_parent.child_nodes as ArrayList<DomNode>).index_of (this);
- if (pos == 0) return null;
- if ((pos - 1) > 0 && (pos - 1) < _parent.child_nodes.size)
- return _parent.child_nodes[pos - 1];
+ if (_parent == null) return null;
+ if (_parent.child_nodes == null) return null;
+ if (_parent.child_nodes.length == 0) return null;
+ var pos = (_parent.child_nodes as ArrayList<DomNode>).index_of (this);
+ if (pos == 0) return null;
+ if ((pos - 1) > 0 && (pos - 1) < _parent.child_nodes.size)
+ return _parent.child_nodes[pos - 1];
+ return null;
}
}
public DomNode? next_sibling {
owned get {
- if (_parent == null) return null;
- if (_parent.child_nodes == null) return null;
- if (_parent.child_nodes.length == 0) return null;
- var pos = (_parent.child_nodes as ArrayList<DomNode>).index_of (this);
- if (pos == 0) return null;
- if ((pos + 1) > 0 && (pos + 1) < _parent.child_nodes.size)
- return _parent.child_nodes[pos + 1];
+ if (_parent == null) return null;
+ if (_parent.child_nodes == null) return null;
+ if (_parent.child_nodes.length == 0) return null;
+ var pos = (_parent.child_nodes as ArrayList<DomNode>).index_of (this);
+ if (pos == 0) return null;
+ if ((pos + 1) > 0 && (pos + 1) < _parent.child_nodes.size)
+ return _parent.child_nodes[pos + 1];
+ return null;
}
}
@@ -108,8 +110,12 @@ public class GXml.GomNode : Object,
return t;
}
set {
- var t = owner_document.create_text_node (text_content);
- child_nodes.add (t);
+ try {
+ var t = owner_document.create_text_node (text_content);
+ child_nodes.add (t);
+ } catch (GLib.Error e) {
+ GLib.warning (_("Text content in element can't be created"));
+ }
}
}
@@ -125,27 +131,16 @@ public class GXml.GomNode : Object,
} catch {}
}
- public bool is_equal_node (DomNode? node) { // FIXME:
+ public bool is_equal_node (DomNode? node) { // FIXME: This is not going to work
if (node == null) return false;
if (this is DomCharacterData)
return (this as DomComment).data == (node as DomComment).data;
- if ((this is DomElement) && (node is DomElement)) {
- if ((this as DomElement).child_nodes.size != (node as DomElement).child_nodes.size) return false;
- foreach (GXml.DomNode a in attributes.values) {
- if (!(node as GXml.Node?).attributes.has_key (a.name)) return false;
- if (a.value != (node as GXml.Node).attributes.get (a.name).value) return false;
- }
- for (int i=0; i < child_nodes.size; i++) {
- if (!((this as DomElement).child_nodes[i] as GXml.DomNode).is_equal_node ((node as
GXml.Node?).child_nodes[i] as GXml.DomNode?)) return false;
- }
- return true;
- }
return false;
}
public DomNode.DocumentPosition compare_document_position (DomNode other) {
if ((this as GXml.DomNode) == other) return DomNode.DocumentPosition.NONE;
- if (this.document != (other as GXml.Node).document || other.parent_node == null) {
+ if (this.owner_document != other.owner_document || other.parent_node == null) {
var p = DomNode.DocumentPosition.DISCONNECTED & DomNode.DocumentPosition.IMPLEMENTATION_SPECIFIC;
if ((&this) > (&other))
p = p & DomNode.DocumentPosition.PRECEDING;
@@ -180,7 +175,7 @@ public class GXml.GomNode : Object,
}
if (this is DomAttr) {
if (this.parent_node == null) return null;
- return this.parent_node.lookup_prefix (nspace);
+ return parent_node.lookup_prefix (nspace);
}
return null;
}
@@ -190,6 +185,10 @@ public class GXml.GomNode : Object,
if (this is DomElement) {
return (this as DomElement).lookup_namespace_uri (prefix);
}
+ if (this is DomAttr) {
+ if (this.parent_node == null) return null;
+ return this.parent_node.lookup_namespace_uri (prefix);
+ }
return null;
}
public bool is_default_namespace (string? nspace) {
@@ -271,42 +270,3 @@ public class GXml.GomNode : Object,
public bool dispatch_event (DomEvent event)
{ return false; } // FIXME:
}
-
-public class GXml.GomAttr : GXml.GomNode {
- protected string _namespace_uri;
- protected string _prefix;
- public string local_name { owned get { return _local_name; } }
- public string name {
- owned get {
- string s = "";
- if (_prefix != null) s = _prefix+":";
- return s+_local_name;
- }
- }
- public string? namespace_uri { owned get { return _namespace_uri; } }
- public string? prefix {
- owned get {
- if (_prefix == "") return null;
- return _prefix;
- }
- }
- public string value { owned get { return _node_value; } set { _node_value = value; } }
-
- public GomAttr (DomElement element, string name, string value) {
- _document = element.owner_document;
- _parent = element;
- _local_name = name;
- _node_value = value;
- }
- public GomAttr.namespace (DomElement element, string namespace, string? prefix, string name, string value)
{
- _document = element.owner_document;
- _parent = element;
- _local_name = name;
- _node_value = value;
- if (element.lookup_prefix (namespace) == prefix
- || (prefix == null && element.lookup_prefix (namespace) == "")) {
- _namespace_uri = namespace;
- _prefix = prefix;
- }
- }
-}
diff --git a/gxml/GomObject.vala b/gxml/GomObject.vala
index 8d40906..574c19b 100644
--- a/gxml/GomObject.vala
+++ b/gxml/GomObject.vala
@@ -53,15 +53,15 @@ public interface GXml.GomObject : GLib.Object,
public virtual string? get_attribute (string name) {
var prop = get_class ().find_property (name);
if (prop != null) {
- if (prop.value_type is SerializableProperty) {
+ if (prop.value_type == typeof(SerializableProperty)) {
var ov = Value(prop.value_type);
get_property (name, ref ov);
- SerializableProperty so = (Object) ov;
+ SerializableProperty so = (Object) ov as SerializableProperty;
if (so == null) return null;
return so.get_serializable_property_value ();
}
}
- return (this as DomElement).get_attribute ();
+ return (this as DomElement).get_attribute (name);
}
/**
* Search for a {@link GLib.Object} property with
@@ -75,14 +75,16 @@ public interface GXml.GomObject : GLib.Object,
public virtual void set_attribute (string name, string val) {
var prop = get_class ().find_property (name);
if (prop != null) {
- if (prop.value_type is SerializableProperty) {
- var ov = get_property (name, ref ov);
- SerializableProperty so = (Object) ov;
+ if (prop.value_type == typeof(SerializableProperty)) {
+ var ov = Value (prop.value_type);
+ get_property (name, ref ov);
+ SerializableProperty so = (Object) ov as SerializableProperty;
if (so == null) return;
so.set_serializable_property_value (val);
+ return;
}
}
- return (this as DomElement).set_attribute (name, val);
+ (this as DomElement).set_property (name, val);
}
/**
* Search a {@link GLib.Object} property with given name
@@ -94,17 +96,28 @@ public interface GXml.GomObject : GLib.Object,
* first {@link DomNode} with that name in child nodes.
*
*/
- public virtual DomElement get_child (string name) {
+ public virtual DomElement? get_child (string name) {
var prop = get_class ().find_property (name);
if (prop != null) {
- if (prop.value_type is DomElement) {
+ if (prop.value_type == typeof(DomElement)) {
var vo = Value(prop.value_type);
get_property (name, ref vo);
return (DomElement) ((Object) vo);
}
}
if ((this as DomNode).has_child_nodes ()) {
- return (this as DomElement).child_nodes.named_item (name);
+ var els = (this as DomElement).get_elements_by_tag_name (name);
+ if (els.size != 0)
+ return els.item (0);
+ }
+ return null;
+ }
+ public virtual void remove_attribute (string name) {
+ var prop = get_class ().find_property (name);
+ if (prop != null) {
+ set_attribute (name, null);
+ return;
}
+ (this as DomElement).remove_attribute (name);
}
}
diff --git a/gxml/Makefile.am b/gxml/Makefile.am
index b2fb497..5a535d9 100644
--- a/gxml/Makefile.am
+++ b/gxml/Makefile.am
@@ -84,6 +84,7 @@ sources = \
GXPathObject.vala \
GomDocument.vala \
GomElement.vala \
+ GomAttr.vala \
GomNode.vala \
GomText.vala \
GomObject.vala \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]