1 /* Demo Recorder for MAEMO 5
2 * Copyright (C) 2010 Dru Moore <usr@dru-id.co.uk>
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2,
5 * or (at your option) any later version, as published by the Free
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 namespace XmlHelpers {
23 public static bool parse_project_settings_file(string location, string version, ref SettingsStructures.ProjectSettings project, ref string errors) {
25 project = SettingsStructures.ProjectSettings();
27 // prepare the Xml Parser
30 Xml.Doc* doc = Xml.Parser.parse_file(location);
33 Xml.Node* root = doc->get_root_element();
35 // check element is ProjectSettings
36 if ("ProjectSettings" == root->name) {
38 string? doc_version = get_node_attribute(root, "version");
39 if (null != doc_version && version == doc_version) {
40 // looking good let's get parsing.
42 project.from_xml_node(root);
45 catch (GLib.Error ex) {
46 errors = "ProjectSettings parser threw an error.";
54 errors = "Incorrect version or unversioned document.";
58 errors = "Not a valid settings file.";
62 errors = "No root node found.";
68 errors = "Couldn't parse file as valid XML.";
70 // clean up the parser
76 private static string? get_node_attribute(Xml.Node* node, string key) {
78 // Loop over the passed node's attributes
79 for (Xml.Attr* prop = node->properties; prop != null; prop = prop->next) {
80 string attr_name = prop->name;
81 // Notice the ->children which points to a Node*
82 // (Attr doesn't feature content)
83 string attr_content = prop->children->content;
84 if (key == attr_name) {