/// <summary> /// Load a Charset collection from a XML file /// </summary> /// <param name="Element"></param> /// <param name="lang"></param> /// <returns></returns> static public CodeBlock CharsetFromXml(XmlElement Element, string lang) { if (Element.Name != "Charset" || string.IsNullOrWhiteSpace(Element.GetAttribute("nameID"))) { throw InvalidXmlCharsetException.DefautMessage; } string name = Element.GetAttribute("nameID"); string newName = GetTextOf(Element, "Name", lang); if (newName != null) { name = newName; } CodeBlock result = new CodeBlock(name); result.Description = GetTextOf(Element, "Description", lang); foreach (XmlElement item in Element.GetElements("Localisable")) { result.Languages = GetTextOf(item, "Languages", lang); result.Countries = GetTextOf(item, "Countries", lang); } foreach (XmlElement item in Element.GetElements("WebCharTable")) { foreach (string attrib in item.GetAttribute("url").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { result.WebCharTable = item.InnerText; } } XmlElement CodeRangeXml = Element.LastElement("CodeRange"); if (CodeRangeXml == null) { throw InvalidXmlCharsetException.DefautMessage; } string codeRangeTxt = ""; foreach (XmlElement Range in CodeRangeXml.GetElements("Range")) { codeRangeTxt += "," + Range.InnerText; } codeRangeTxt = CodePoint.CleanCoderange(codeRangeTxt); if (string.IsNullOrWhiteSpace(codeRangeTxt)) { throw InvalidXmlCharsetException.DefautMessage; } result.CodePoints = CodePoint.RangeFromString(codeRangeTxt); return(result); }
/// <summary> /// Get the code Block from a XmlElement /// </summary> static public CodeBlock LoadFromXml(XmlElement Element, string lang) { if (Element.Name != "Block" || string.IsNullOrWhiteSpace(Element.GetAttribute("nameID"))) { throw InvalidXmlBlockException.DefautMessage; } string name = Element.GetAttribute("nameID"); string newName = GetTextOf(Element, "Name", lang); if (newName != null) { name = newName; } CodeBlock result = new CodeBlock(name); result.Description = GetTextOf(Element, "Description", lang); foreach (XmlElement item in Element.GetElements("Localisable")) { result.Languages = GetTextOf(item, "Languages", lang); result.Countries = GetTextOf(item, "Countries", lang); } foreach (XmlElement item in Element.GetElements("WebCharTable")) { result.WebCharTable = item.GetAttribute("url"); } XmlElement CodeRangeXml = Element.LastElement("CodeRange"); if (CodeRangeXml == null) { throw InvalidXmlCharsetException.DefautMessage; } if (string.IsNullOrWhiteSpace(CodeRangeXml.GetAttribute("start")) || string.IsNullOrWhiteSpace(CodeRangeXml.GetAttribute("end"))) { throw InvalidXmlBlockException.DefautMessage; } result.CodeStart = new Hexa(CodeRangeXml.GetAttribute("start")); result.CodeEnd = new Hexa(CodeRangeXml.GetAttribute("end")); string codeRangeTxt = ""; foreach (XmlElement Range in CodeRangeXml.GetElements("Range")) { codeRangeTxt += "," + Range.InnerText; } codeRangeTxt = CodePoint.CleanCoderange(codeRangeTxt); if (string.IsNullOrWhiteSpace(codeRangeTxt)) { throw InvalidXmlBlockException.DefautMessage; } result.CodePoints = CodePoint.RangeFromString(codeRangeTxt); return(result); }