适用于C#的Gedcom读卡器

有没有人知道一个好的类来读取.ged文件

Gedcom是一种用于存储宗谱信息的文件格式。

我的目标是写一些东西,让我导入一个ged文件并导出.vot文件for graphviz,这样我就可以直观地表示一个家谱

谢谢,如果你能提供帮助

到目前为止,这是我最好的尝试。

它似乎正在为我需要的东西工作,虽然它绝对不是完全certificate(然后我的家谱再次相当大,这增加了一些复杂性)

如果你认为我可以做更多的事情,请告诉我

struct INDI { public string ID; public string Name; public string Sex; public string BirthDay; public bool Dead; } struct FAM { public string FamID; public string type; public string IndiID; } List Individuals = new List(); List Family = new List(); private void button1_Click(object sender, EventArgs e) { string path = @"C:\mostrecent.ged"; ParseGedcom(path); } private void ParseGedcom(string path) { //Open path to GED file StreamReader SR = new StreamReader(path); //Read entire block and then plit on 0 @ for individuals and familys (no other info is needed for this instance) string[] Holder = SR.ReadToEnd().Replace("0 @", "\u0646").Split('\u0646'); //For each new cell in the holder array look for Individuals and familys foreach (string Node in Holder) { //Sub Split the string on the returns to get a true block of info string[] SubNode = Node.Replace("\r\n", "\r").Split('\r'); //If a individual is found if (SubNode[0].Contains("INDI")) { //Create new Structure INDI I = new INDI(); //Add the ID number and remove extra formating I.ID = SubNode[0].Replace("@", "").Replace(" INDI", "").Trim(); //Find the name remove extra formating for last name I.Name = SubNode[FindIndexinArray(SubNode, "NAME")].Replace("1 NAME", "").Replace("/", "").Trim(); //Find Sex and remove extra formating I.Sex = SubNode[FindIndexinArray(SubNode, "SEX")].Replace("1 SEX ", "").Trim(); //Deterine if there is a brithday -1 means no if (FindIndexinArray(SubNode, "1 BIRT ") != -1) { // add birthday to Struct I.BirthDay = SubNode[FindIndexinArray(SubNode, "1 BIRT ") + 1].Replace("2 DATE ", "").Trim(); } // deterimin if there is a death tag will return -1 if not found if (FindIndexinArray(SubNode, "1 DEAT ") != -1) { //convert Y or N to true or false ( defaults to False so no need to change unless Y is found. if (SubNode[FindIndexinArray(SubNode, "1 DEAT ")].Replace("1 DEAT ", "").Trim() == "Y") { //set death I.Dead = true; } } //add the Struct to the list for later use Individuals.Add(I); } // Start Family section else if (SubNode[0].Contains("FAM")) { //grab Fam id from node early on to keep from doing it over and over string FamID = SubNode[0].Replace("@ FAM", ""); // Multiple children can exist for each family so this section had to be a bit more dynaimic // Look at each line of node foreach (string Line in SubNode) { // If node is HUSB if (Line.Contains("1 HUSB ")) { FAM F = new FAM(); F.FamID = FamID; F.type = "PAR"; F.IndiID = Line.Replace("1 HUSB ", "").Replace("@","").Trim(); Family.Add(F); } //If node for Wife else if (Line.Contains("1 WIFE ")) { FAM F = new FAM(); F.FamID = FamID; F.type = "PAR"; F.IndiID = Line.Replace("1 WIFE ", "").Replace("@", "").Trim(); Family.Add(F); } //if node for multi children else if (Line.Contains("1 CHIL ")) { FAM F = new FAM(); F.FamID = FamID; F.type = "CHIL"; F.IndiID = Line.Replace("1 CHIL ", "").Replace("@", ""); Family.Add(F); } } } } } private int FindIndexinArray(string[] Arr, string search) { int Val = -1; for (int i = 0; i < Arr.Length; i++) { if (Arr[i].Contains(search)) { Val = i; } } return Val; } 

在Codeplex: FamilyShow (WPF展示)中有一个非常漂亮的。 它import/出口GEDCOM 5.5并且有来源。

如果至少没有一个人的开头,我真的会感到惊讶。 我很容易找到Gedcom.NET ( sourceforge )

如果网上有这种格式的C#阅读器,我会感到非常惊讶,因为它是一种相当专业的格式。 从好的方面来说,如果您需要创建自己的阅读器,则格式看起来非常简单。 如果您对实施有具体问题,我建议您沿着这条道路前进并返回SO。 看一下System.IO.StreamReader类; 以这种方式逐行读取文件是微不足道的,解析各行也应该很简单。

祝好运!