public bool parse() { var fi = new System.IO.FileInfo(qrcFileName); if (!fi.Exists) { return(false); } try { var reader = new XmlTextReader(qrcFileName); QrcItem currentItem = null; QrcPrefix currentPrefix = null; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.LocalName.ToLower() == "qresource") { currentPrefix = new QrcPrefix(); currentPrefix.Prefix = reader.GetAttribute("prefix"); currentPrefix.Language = reader.GetAttribute("lang"); prefixes.Push(currentPrefix); } else if (reader.LocalName.ToLower() == "file") { currentItem = new QrcItem(); currentItem.Alias = reader.GetAttribute("name"); } break; case XmlNodeType.EndElement: if (reader.LocalName.ToLower() == "qresource") { prefxs.Add(prefixes.Pop()); } else if (reader.LocalName.ToLower() == "file" && prefixes.Peek() != null && currentItem != null) { prefixes.Peek().AddQrcItem(currentItem); currentItem = null; } break; case XmlNodeType.Text: if (currentItem != null) { currentItem.Path = reader.Value; } break; } } reader.Close(); } catch (System.Exception) { return(false); } return(true); }
public void AddQrcItem(QrcItem item) { Items.Add(item); }