소스코드

using System.Xml.Linq;

namespace XMLSample
{
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
           
            WebClient wc = new WebClient();
            //이벤트 등록
            wc.DownloadStringCompleted +=
                new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);                            
            wc.DownloadStringAsync(new Uri("Outer.xml", UriKind.RelativeOrAbsolute));         
        }

        void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            XDocument xDoc = XDocument.Parse(e.Result); // 외부에 존재하는 XML 파일을 읽을 경우

            var linq = from c in xDoc.Descendants("Item")
                       select (string)c.Value;

            foreach (string item in linq)
            {
                tbOuter.Text += item + "\n";
            }
        }
    }
}


XML 소스
<?xml version="1.0" encoding="utf-8" ?>
<Items>
  <Item>Car</Item>
  <Item>Road</Item>
  <Item>Tree</Item>
  <Item>Park</Item>
  <Item>Mountain</Item>
</Items>


Posted by 맨날맑음

댓글을 달아 주세요

  1. Favicon of http://livedk.textcube.com BlogIcon livedk 2008.12.20 22:32  댓글주소  수정/삭제  댓글쓰기

    님 짱임^^

  2. Favicon of http://fkfkfk6399.vfm.kr/ BlogIcon 강천구 2010.02.01 09:54  댓글주소  수정/삭제  댓글쓰기

    감사해요