문제
누구든지 .ged 파일에서 읽을 수있는 좋은 수업을 알고 있습니까?
GEDCOM은 계보 정보를 저장하는 데 사용되는 파일 형식입니다.
내 목표는 GED 파일을 가져오고 Family Tree를 시각적으로 표현할 수 있도록 GHED 파일을 가져 와서 .DOT 파일을 내보낼 수있는 것을 작성하는 것입니다.
도와 드릴 수 있다면 감사합니다
해결책
그녀는 지금까지 나의 최선의 시도입니다.
그것은 무의미하게 완전한 증거가 아니지만 필요한 것에 대해 효과가있는 것 같습니다 (다시 내 가계도는 다소 크고 복잡성이 더해집니다).
내가 더 적합한 것을 만들 수 있다고 생각되면 알려주세요.
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<INDI> Individuals = new List<INDI>();
List<FAM> Family = new List<FAM>();
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에는 매우 예쁜 것이 있습니다. 가족 쇼 (WPF 쇼케이스). GEDCOM 5.5를 수입/내보내며 소스가 있습니다.
나는 실제로 거기에 놀랐을 것입니다 그렇지 않았습니다 적어도 하나의 시작. 나는 찾았다 gedcom.net (Sourceforge) 꽤 쉽게
상당히 전문화 된 형식이라는 점을 감안할 때 웹 에서이 형식에 대한 C# 리더가 있다면 상당히 놀랄 것입니다. 거꾸로, 형식은 자신의 독자를 만들어야한다면 읽기가 매우 간단한 것으로 보입니다. 구현에 대한 구체적인 질문이 있다면 그 길을 따라 가서 돌아 오는 것이 좋습니다. 살펴보십시오 System.IO.StreamReader
수업; 그런 식으로 파일로 파일로 읽는 것은 사소한 일이며 개별 라인을 구문 분석하는 것도 간단해야합니다.
행운을 빕니다!
제휴하지 않습니다 StackOverflow