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>
#리스트
#생성
list = []
list = [100, 200, 300]
list.append(400) #추가
list #출력
buy_list = ['Naver', 500]
buy_list[0] #인덱싱 출력
kospi_top5 = ['삼성전자', 'SK하이닉스', '현대차', '한국전력', '아모레퍼시픽']
kospi_top3 = kospi_top5[0:3] #슬라이싱
kospi_top3 #출력 => ['삼성전자', 'SK하이닉스', '현대차']
# 삽입
buy_list.insert(2, 'Daum')
buy_list
#삭제
del buy_list[1]
buy_list
len(buy_list)
#튜플
#리스트는 리스트 내의 원소를 변경할 수 있지만
#튜플은 변경 불가능. 즉, 변경없는 데이터는 튜플로 하면 빠르다!
tuple =()
t = ('Samsun', 'LG', 'SK')
t
len(t)
t[1]
#t[0] = "Naver" #err tuple' object does not support item assignment
#슬라이싱
t[0:2]
#딕셔너리 = 사전
#키와 값의 쌍으로 저장
#순서가 없기에 인덱싱 지원 안함.
#키를 통해서 검색한다.
dictionary = {}
type(dictionary)
dictionary['Naver'] = 300000
dictionary #{'Naver': 300000}
#del dictionary['Naver']
#dictionary #{}
dictionary.keys()
dictionary.values()