# HG changeset patch # User IBBoard # Date 1237741501 0 # Node ID d0812d7de39dc66de3924e9e19a83e875a23c833 # Parent d0d44434b557eaf1f6ae48057f306e8f4edcb4fb Re #49 - Resolve namespace issues * Fix up some XPath queries * Remove one unnecessary namespace * Check local name of elements, not name (which is qualified) * Add method to get double value from an attribute including handling INF * Remove min/max for equipment item as it is now moved to the UnitType's reference to the equipment item * diff -r d0d44434b557 -r d0812d7de39d api/Factories/Xml/WarFoundryXmlFactory.cs --- a/api/Factories/Xml/WarFoundryXmlFactory.cs Sun Mar 22 16:37:43 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlFactory.cs Sun Mar 22 17:05:01 2009 +0000 @@ -65,7 +65,7 @@ XmlDocument doc = CreateXmlDocumentFromStream(stream); XmlElement elem = (XmlElement)doc.LastChild; - if (!elem.Name.Equals(elementName.Value)) + if (!elem.LocalName.Equals(elementName.Value)) { throw new InvalidFileException(String.Format("Root element of XML was not valid. Expected {0} but got {1}", elementName.Value, elem.Name)); } @@ -198,9 +198,9 @@ XmlNode elem = GetExtraData(system); LoadCategoriesForSystem(system, elem); - XmlNodeList nodeList = SelectNodes(elem, "/system:system/system:categories"); + XmlNodeList nodeList = SelectNodes(elem, "/system:system/system:sysStatsList"); XmlNode statsElem = nodeList.Item(0); - string defaultStatsID = ((XmlElement)statsElem).GetAttribute("defaultStats", "http://ibboard.co.uk/warfoundry/system"); + string defaultStatsID = ((XmlElement)statsElem).GetAttribute("defaultStats"); LoadSystemStatsForSystem(system, elem); system.StandardSystemStatsID = defaultStatsID; LogNotifier.DebugFormat(GetType(), "Completed loading of GameSystem with ID {0}", system.Name); @@ -212,7 +212,7 @@ { WarFoundryObject tempObj; - foreach (XmlElement cat in SelectNodes(elem, "/system:system/system:categories/cat:category")) + foreach (XmlElement cat in SelectNodes(elem, "/system:system/system:categories/cat:cat")) { tempObj = CreateObjectFromElement(cat); @@ -377,7 +377,7 @@ WarFoundryObject obj = null; LogNotifier.DebugFormat(GetType(), "Create object for <{0}>", elem.Name); - if (elem.Name.Equals(WarFoundryXmlElementName.CATEGORY_ELEMENT.Value)) + if (elem.LocalName.Equals(WarFoundryXmlElementName.CATEGORY_ELEMENT.Value)) { LogNotifier.Debug(GetType(), "Create Category"); obj = CreateCategoryFromElement(elem); @@ -413,6 +413,30 @@ throw new FormatException(String.Format("Attribute '{0}' of {1} with ID {2} was not a valid number", attributeName, elem.Name, elem.GetAttribute("id"))); } } + + private double GetDoubleValueFromAttribute(XmlElement elem, string attributeName) + { + double doubleVal = double.NaN; + string attribValue = elem.GetAttribute(attributeName); + + if (attribValue == "INF") + { + doubleVal = double.PositiveInfinity; + } + else + { + try + { + return int.Parse(attribValue); + } + catch(FormatException) + { + throw new FormatException(String.Format("Attribute '{0}' of {1} with ID {2} was not a valid number", attributeName, elem.Name, elem.GetAttribute("id"))); + } + } + + return doubleVal; + } private UnitType CreateUnitTypeFromElement(XmlElement elem, Race parentRace, GameSystem system) { @@ -500,43 +524,27 @@ { string id = elem.GetAttribute("id"); string name = elem.GetAttribute("name"); - float cost = 0, min = 0, max = 0; + double cost = 0, min = 0, max = 0; ArmourType armourType; try { - cost = float.Parse(elem.GetAttribute("cost")); - } - catch(FormatException) - { - throw new FormatException("Attribute 'cost' of equipment item "+id+" was not a valid number"); - } - - try - { - min = float.Parse(elem.GetAttribute("min")); + cost = GetDoubleValueFromAttribute(elem, "cost"); } - catch(FormatException) - { - throw new FormatException("Attribute 'min' of equipment item "+id+" was not a valid number"); - } - - try + catch(FormatException ex) { - max = float.Parse(elem.GetAttribute("max")); - } - catch(FormatException) - { - throw new FormatException("Attribute 'max' of equipment item "+id+" was not a valid number"); - } + throw new InvalidFileException("Attribute 'cost' of equipment item "+id+" was not a valid number", ex); + } try { armourType = (ArmourType)Enum.Parse(typeof(ArmourType), elem.GetAttribute("armourType")); } - catch(FormatException) + catch(ArgumentException ex) { - throw new InvalidFileException("Attribute 'armourType' of equipment "+id+" was not a valid value from the enumeration"); + //throw new InvalidFileException("Attribute 'armourType' of equipment "+id+" was not a valid value from the enumeration"); + LogNotifier.WarnFormat(GetType(), "Invalid 'armourType' for equipment {0} - {1}", id, ex.Message); + armourType = ArmourType.None; } if (elem.ChildNodes.Count>0) diff -r d0d44434b557 -r d0812d7de39d api/Objects/EquipmentItem.cs --- a/api/Objects/EquipmentItem.cs Sun Mar 22 16:37:43 2009 +0000 +++ b/api/Objects/EquipmentItem.cs Sun Mar 22 17:05:01 2009 +0000 @@ -12,11 +12,11 @@ /// public class EquipmentItem : WarFoundryObject { - private float cost, min, max; + private double cost, min, max; private ArmourType armourType; private Race equipForRace; - public EquipmentItem(string id, string name, float itemCost, float minimum, float maximum, ArmourType itemArmourType, Race race) : base(id, name) + public EquipmentItem(string id, string name, double itemCost, double minimum, double maximum, ArmourType itemArmourType, Race race) : base(id, name) { cost = itemCost; min = minimum; @@ -30,7 +30,7 @@ get { return ((MaxNumber < 1 && MaxNumber > 0) || (MaxNumber == 1 && MinNumber > 0)); } } - public float MinNumber + public double MinNumber { get { return min; } set @@ -44,7 +44,7 @@ } } - public float MaxNumber + public double MaxNumber { get { return max; } set @@ -64,7 +64,7 @@ set { armourType = value; } } - public float Cost + public double Cost { get { return cost; } set { cost = value; } diff -r d0d44434b557 -r d0812d7de39d api/Objects/GameSystem.cs --- a/api/Objects/GameSystem.cs Sun Mar 22 16:37:43 2009 +0000 +++ b/api/Objects/GameSystem.cs Sun Mar 22 17:05:01 2009 +0000 @@ -80,6 +80,7 @@ { get { + EnsureFullyLoaded(); return stats[defaultStats]; } } diff -r d0d44434b557 -r d0812d7de39d dtds/race.xsd --- a/dtds/race.xsd Sun Mar 22 16:37:43 2009 +0000 +++ b/dtds/race.xsd Sun Mar 22 17:05:01 2009 +0000 @@ -62,8 +62,8 @@ - - + + @@ -127,7 +127,7 @@ - + diff -r d0d44434b557 -r d0812d7de39d dtds/warfoundry-core.xsd --- a/dtds/warfoundry-core.xsd Sun Mar 22 16:37:43 2009 +0000 +++ b/dtds/warfoundry-core.xsd Sun Mar 22 17:05:01 2009 +0000 @@ -30,4 +30,13 @@ + + + + + + + + + \ No newline at end of file