changeset 27:4ea1fc351533

Re #18 - Migrate XML tools * Add method to get an attribute as a boolean
author IBBoard <dev@ibboard.co.uk>
date Sat, 28 Mar 2009 20:54:01 +0000
parents 14f3daf48ba5
children 41ddcd61dc92
files Xml/XmlTools.cs
diffstat 1 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Xml/XmlTools.cs	Sat Mar 28 20:37:40 2009 +0000
+++ b/Xml/XmlTools.cs	Sat Mar 28 20:54:01 2009 +0000
@@ -14,6 +14,30 @@
 	public class XmlTools
 	{			
 		/// <summary>
+		/// Gets the value of an attribute of an element as a boolean. Throws a FormatException if the attribute is not a boolean.
+		/// </summary>
+		/// <param name="elem">
+		/// The <see cref="XmlElement"/> to get the attribute value of
+		/// </param>
+		/// <param name="attributeName">
+		/// The name of the attribute to get as a boolean
+		/// </param>
+		/// <returns>
+		/// The value of the attribute as an boolean
+		/// </returns>
+		public static bool GetBoolValueFromAttribute(XmlElement elem, string attributeName)
+		{
+			try
+			{
+				return bool.Parse(elem.GetAttribute(attributeName));
+			}
+			catch(FormatException)
+			{
+				throw new FormatException(String.Format("Attribute '{0}' of {1} with ID {2} was not a valid boolean", attributeName, elem.Name, elem.GetAttribute("id")));
+			}
+		}
+		
+		/// <summary>
 		/// Gets the value of an attribute of an element as an integer. Throws a FormatException if the attribute is not an integer.
 		/// </summary>
 		/// <param name="elem">