Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/3.2/XmlSupport.cs @ 2211

Last change on this file since 2211 was 1993, checked in by mstoeger, 15 years ago

added many new persisted properties.
removed useless comments.
added XmlSupport class since the code for setting xml attributes is always the same.
#639

File size: 913 bytes
Line 
1using System;
2using System.Xml;
3
4namespace HeuristicLab.Visualization {
5  public static class XmlSupport {
6    public static void SetAttribute(string name, string value, XmlNode element) {
7      XmlAttribute attributeNode = element.OwnerDocument.CreateAttribute(name);
8      attributeNode.Value = value;
9      element.Attributes.Append(attributeNode);
10    }
11
12    public static string GetAttribute(string name, string @default, XmlNode element) {
13      XmlAttribute attributeNode = element.Attributes[name];
14
15      if (attributeNode == null)
16        return @default;
17      else
18        return attributeNode.Value;
19    }
20
21    public static string GetAttribute(string name, XmlNode element) {
22      string value = GetAttribute(name, null, element);
23
24      if (value == null)
25        throw new Exception(string.Format("Attribute '{0}' not found.", name));
26
27      return value;
28    }
29  }
30}
Note: See TracBrowser for help on using the repository browser.