private void btn_Add_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
try
{
// 파일 열기 대화상자를 생성
OpenFileDialog dlg = new OpenFileDialog();
// 사용자가 파일을 선택했는지 확인
if(dlg.ShowDialog() == DialogResult.OK)
{
// XML 문서를 로드하기 위한 XmlDocument 객체 생성
XmlDocument doc = new XmlDocument();
// 사용자가 선택한 XML 파일을 로드
doc.Load(dlg.FileName);
// XML 내의 모든 Message 노드를 가져오기
// XPath 쿼리를 사용하여 A아래의 B노드들을 선택
XmlNodeList messageNodes = doc.SelectNodes("/A/B");
foreach (XmlNode messageNode in messageNodes)
{
// <B> 노드의 id 속성 값
string messageId = messageNode.Attributes["id"].Value;
// <B> 하위의 <one>, <two>, <three> 값 추출
string ONE = messageNode.SelectSingleNode("one")?.InnerText.Trim();
string TWO = messageNode.SelectSingleNode("two")?.InnerText.Trim();
string THREE = messageNode.SelectSingleNode("three")?.InnerText.Trim();
// 데이터베이스에 메시지를 저장하는 메서드 호출
this.{db 불러오는 형식}.(messageId, ONE, TWO, THREE);
}
}
}
catch(Exception ex)
{
}
}
별도로 체크해야할 것
1. .XML의 구조
<?xml version="1.0"?> <!-- ================================================================ --> <!-- 정보 --> <!-- 정보~ --> <!-- ================================================================ --> <A> <B id="WHAT"> <one>information</one > <two> information </two > <three>information</three > </B> <B id="how"> <one> information </one > <two> information </two > <three> information </three > </B> </A>
public class 함수명
{
public string Key { get; set; }
public clsEnum.{Values} Value { get; set; }
public 함수명(clsEnum.{Values} Key, string value) 생성자
{
Key = key;
Value = value;
}
public override string ToString()
{
return Value; ComboBox에 표시할 텍스트
}
}
이런식으로 사용하라는데;;
그냥 Dictionary<string, string> dicTemp = new Dictionary<string, string>(); 이거쓰면 한 줄에 가능.