The Birdfont Source Code


All Repositories / xmlbird.git / commit – RSS feed

Parse attributes in XML elements

These changes was commited to the Birdfont repository Mon, 11 Jan 2016 21:03:59 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/xmlbird.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Mon, 11 Jan 2016 21:03:59 +0000 (22:03 +0100)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Mon, 11 Jan 2016 21:03:59 +0000 (22:03 +0100)
commit bbd4a7dc20a79484fa16c293d914998cea584e8c
tree e7b2a00e5f54fc0b7b3d82472bcbcc9890d8f585
parent a07f508a1256a3191265b378c8379e64a445b177
Parse attributes in XML elements

libxmlbird/Attributes.vala
libxmlbird/XmlElement.vala
--- a/libxmlbird/Attributes.vala +++ b/libxmlbird/Attributes.vala @@ -17,7 +17,6 @@ * Iterator for XML attributes. */ public class Attributes : GLib.Object { - Tag? tag = null; Elements? elements = null;
--- a/libxmlbird/XmlElement.vala +++ b/libxmlbird/XmlElement.vala @@ -33,14 +33,21 @@ name = tag.get_name (); xml_namespace = tag.get_namespace (); this.parent = parent; - - leaf = !tag.has_more_tags (); + + children = parse_tags (tag); + attributes = parse_attributes (tag); + + leaf = children == null; if (leaf) { content = tag.get_content (); - } else { - children = parse_tags (tag); } + } + + internal XmlElement.attribute (Attribute attribute) { + name = attribute.get_name (); + xml_namespace = attribute.get_namespace (); + content = attribute.get_content (); } ~XmlElement () { @@ -61,16 +68,35 @@ parent = null; } - internal Elements parse_tags (Tag tag) { + internal Elements? parse_tags (Tag tag) { Elements elements = new Elements (); foreach (Tag t in tag) { elements.add (new XmlElement (this, t)); } - + + if (elements.size == 0) { + return null; + } + return elements; } - + + internal Elements? parse_attributes (Tag tag) { + Attributes tag_attributes = tag.get_attributes (); + Elements elements = new Elements (); + + foreach (Attribute a in tag_attributes) { + elements.add (new XmlElement.attribute (a)); + } + + if (elements.size == 0) { + return null; + } + + return elements; + } + /** Get a reference to the parent element. This method will return * null if the parent element has been deleted, if the method is called * on the root element or if the method is called on an attribute. @@ -82,6 +108,10 @@ XmlElement e = (!) parent; return e; + } + + public bool is_leaf () { + return leaf; } public string get_name () {