소스코드

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 맨날맑음