private async static Task <UnicodeData[]> ReadXmlFile(string fileName) { Task <UnicodeData[]> t = Task.Run(() => { IEnumerable <XElement> level1Element = XElement.Load(fileName).Elements("ul"); int j = 0; UnicodeData[] list = new UnicodeData[level1Element.Elements("li").Count()]; foreach (XElement level2Element in level1Element.Elements("li")) { if (level2Element.Attribute("class") != null && level2Element.Attribute("class").Value.ToLower().StartsWith("symb")) { if (level2Element.Attribute("class").Value.ToLower().Contains("inactive")) { list[j] = new UnicodeData() { Name = level2Element.Value, IsLeaf = true, Inactive = true, }; } else { list[j] = new UnicodeData() { Name = level2Element.Value, IsLeaf = true, DataCode = int.Parse(level2Element.Attribute("data-code").Value), Code = level2Element.Attribute("code").Value, Title = level2Element.Attribute("title").Value, }; } } else if (level2Element.Attribute("class") != null && level2Element.Attribute("class").Value.ToLower() == "h") { list[j] = new UnicodeData() { Name = level2Element.Value.Trim(), IsLeaf = false, Code = level2Element.Value.Trim(), Title = "", }; list[j].DataCode = Convert.ToInt32("0x" + list[j].Code, 16); } j++; if (j == list.Length) { j = 0; } } return(list); }); UnicodeData[] res = await t; return(res); }
private static UnicodeData[][] ReadXml() { IEnumerable <XElement> IEXelem = XElement.Load(@".\unicode-table.xml").Elements("ul"); int i = 0, j = 0; UnicodeData[][] array2D = new UnicodeData[IEXelem.Count()][]; foreach (XElement level1Element in IEXelem) { UnicodeData[] list = new UnicodeData[level1Element.Elements("li").Count()]; foreach (XElement level2Element in level1Element.Elements("li")) { if (level2Element.Attribute("class") != null && level2Element.Attribute("class").Value.ToLower().StartsWith("symb")) { list[j] = new UnicodeData() { Name = level2Element.Value, IsLeaf = true, DataCode = int.Parse(level2Element.Attribute("data-code").Value), Code = level2Element.Attribute("title") == null ? "" : level2Element.Attribute("title").Value.Split(new char[] { '|' })[0].Trim().Substring(2), Title = level2Element.Attribute("title") == null ? "" : level2Element.Attribute("title").Value }; } else if (level2Element.Attribute("class") != null && level2Element.Attribute("class").Value.ToLower() == "h") { list[j] = new UnicodeData() { Name = level2Element.Value.Trim(), IsLeaf = false, Code = level2Element.Value.Trim(), Title = "", }; list[j].DataCode = Convert.ToInt32("0x" + list[j].Code, 16); } j++; if (j == list.Length) { j = 0; } } array2D[i] = list; i++; } return(array2D); }
private async static Task <UnicodeData[]> ReadXml(string source) { Task <UnicodeData[]> t = Task.Run(() => { IEnumerable <XElement> IEXelem = XElement.Parse(source).Descendants("ul"); XElement level1Element = null; foreach (XElement level1ElementT in IEXelem) { if (level1ElementT.Attribute("class") != null && level1ElementT.Attribute("class").Value.ToLower().StartsWith("unicode_table")) { level1Element = level1ElementT; break; } } if (level1Element == null) { return(new UnicodeData[0]); } int j = 0; UnicodeData[] list = new UnicodeData[level1Element.Elements("li").Count()]; foreach (XElement level2Element in level1Element.Elements("li")) { if (level2Element.Attribute("class") != null && level2Element.Attribute("class").Value.ToLower().StartsWith("symb")) { if (level2Element.Attribute("class").Value.ToLower().Contains("inactive")) { list[j] = new UnicodeData() { Name = level2Element.Value, IsLeaf = true, Inactive = true, }; } else { list[j] = new UnicodeData() { Name = level2Element.Value, IsLeaf = true, Code = level2Element.Element("a").Attribute("href").Value.Split(new char[] { '/' })[2].Trim(), Title = level2Element.Attribute("title").Value, }; list[j].DataCode = Convert.ToInt32("0x" + list[j].Code, 16); } } else if (level2Element.Attribute("class") != null && level2Element.Attribute("class").Value.ToLower() == "h") { list[j] = new UnicodeData() { Name = level2Element.Value.Trim(), IsLeaf = false, Code = level2Element.Value.Trim(), Title = "", }; list[j].DataCode = Convert.ToInt32("0x" + list[j].Code, 16); } j++; if (j == list.Length) { j = 0; } } return(list); }); UnicodeData[] res = await t; return(res); }