private static void ReadReading(Kanji kanji, XmlReader reader) { if (reader.NodeType != XmlNodeType.None) { string rtype = reader.GetAttribute("r_type"); if (rtype.Equals("ja_on")) { kanji.Reading.On.Add(reader.ReadElementContentAsString()); } else if (rtype.Equals("ja_kun")) { kanji.Reading.Kun.Add(reader.ReadElementContentAsString()); } } }
private static Kanji ReadKanji(XmlReader reader) { var kanji = new Kanji(); reader.ReadToDescendant("literal"); kanji.Character = reader.ReadElementContentAsString(); if (reader.ReadToFollowing("misc")) { ReadMisc(kanji, reader.ReadSubtree()); } if (reader.ReadToFollowing("reading_meaning")) { ReadReadingMeaning(kanji, reader.ReadSubtree()); } reader.Close(); return(kanji); }
private void WriteKanji(Kanji kanji, StreamWriter sw) { var sb = new StringBuilder(); sb.Append(kanji.Character); sb.Append(";"); for (int i = 0; i < kanji.Meanings.Count && i < _maxMeanings; i++) { string meaning = kanji.Meanings[i]; sb.Append(meaning); int min = Math.Min(kanji.Meanings.Count, _maxMeanings); // control extra commas if (i < min - 1) { sb.Append(", "); } } sb.Append(";"); for (int i = 0; i < kanji.Reading.Kun.Count && i < _maxReadings; i++) { string kunReading = kanji.Reading.Kun[i]; sb.Append(kunReading); int min = Math.Min(kanji.Reading.Kun.Count, _maxReadings); if (i < min - 1) { sb.Append(", "); } } sb.Append(";"); for (int i = 0; i < kanji.Reading.On.Count && i < _maxReadings; i++) { string onReading = kanji.Reading.On[i]; sb.Append(onReading); int min = Math.Min(kanji.Reading.On.Count, _maxReadings); if (i < min - 1) { sb.Append(", "); } } sb.Append(";"); sb.Append(kanji.JLPT); sw.WriteLine(sb.ToString()); }
public static void ReadRMGroup(Kanji kanji, XmlReader reader) { //if (reader.ReadToDescendant("reading")) //{ // ReadReading(kanji, reader); // while (reader.ReadToNextSibling("reading")) // { // ReadReading(kanji, reader); // } //} //if (reader.ReadToDescendant("meaning")) //{ // if (reader.NodeType != XmlNodeType.None) // kanji.Meanings.Add(reader.ReadElementContentAsString()); // while (reader.ReadToNextSibling("meaning")) // { // kanji.Meanings.Add(reader.ReadElementContentAsString()); // } //} while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.None: break; case XmlNodeType.Element: if (reader.Name == "reading") { if (reader.NodeType != XmlNodeType.None) { ReadReading(kanji, reader); } } else if (reader.Name == "meaning") { if (reader.NodeType != XmlNodeType.None) { kanji.Meanings.Add(reader.ReadElementContentAsString()); } } break; case XmlNodeType.Attribute: break; case XmlNodeType.Text: break; case XmlNodeType.CDATA: break; case XmlNodeType.EntityReference: break; case XmlNodeType.Entity: break; case XmlNodeType.ProcessingInstruction: break; case XmlNodeType.Comment: break; case XmlNodeType.Document: break; case XmlNodeType.DocumentType: break; case XmlNodeType.DocumentFragment: break; case XmlNodeType.Notation: break; case XmlNodeType.Whitespace: break; case XmlNodeType.SignificantWhitespace: break; case XmlNodeType.EndElement: break; case XmlNodeType.EndEntity: break; case XmlNodeType.XmlDeclaration: break; default: throw new ArgumentOutOfRangeException(); } } reader.Close(); }
public static void ReadReadingMeaning(Kanji kanji, XmlReader reader) { reader.ReadToDescendant("rmgroup"); ReadRMGroup(kanji, reader.ReadSubtree()); reader.Close(); }