public void Setup() { _dictionary = new Jmdictionary(); _dictionary.Append("a", "1"); _dictionary.Append("b", "2"); _dictionary.Append("b", "3"); }
void CreateDictionary() { using (var nodes = _document.SelectNodes($"/JMdict/entry/k_ele/keb[text()]")) { foreach (XmlElement n in nodes) { var gloss = n.ParentNode.ParentNode.SelectSingleNode("sense/gloss"); if (gloss != null) { _dictionary.Append(n.InnerXml, gloss.InnerXml); } } } }
void ReadDictionary() { using (var stream = new StreamReader(_path)) using (var reader = new XmlTextReader(stream) { WhitespaceHandling = WhitespaceHandling.None, Namespaces = false }) { string result = null; if (reader.ReadToDescendant("entry")) { while (result == null && reader.ReadToNextSibling("entry")) { if (reader.NodeType == XmlNodeType.Element) { string word = null; using (var subr = reader.ReadSubtree()) { while (subr.Read()) { if (subr.Name == "keb" && subr.NodeType == XmlNodeType.Element) { word = subr.ReadElementContentAsString(); } else if (word != null && subr.Name == "gloss" && subr.NodeType == XmlNodeType.Element) { _dictionary.Append(word, subr.ReadElementContentAsString()); } } } } } } } }