2017-12-31 61 views
0

C#을 사용하여 UWP의 서버에 저장된 XML 파일을 어떻게 읽습니까? 나는 XML 파일을 다운로드 시도하고이 코드를 사용하여 읽는 것 : 나는 응용 프로그램을 실행하면uwp에서 xml 파일을 읽는 방법

StorageFolder storageFolder = ApplicationData.Current.LocalFolder; 
Uri address = new Uri("https://www.dropbox.com/s/lyf9lv03dogidb9/home.xml?dl=1"); 
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address); 
WebResponse response = await request.GetResponseAsync(); 
Stream stream = response.GetResponseStream(); 
StorageFile XMLfile = await storageFolder.CreateFileAsync("homemv.xml", CreationCollisionOption.ReplaceExisting); 
await Windows.Storage.FileIO.WriteBytesAsync(XMLfile, ReadStream(stream)); 
//load data into flip view 
StorageFile tempFile = await ApplicationData.Current.LocalFolder.GetFileAsync("homemv.xml"); 
String datas = await FileIO.ReadTextAsync(tempFile); 
XDocument loadedData = XDocument.Load(datas); 
var data = from query in loadedData.Descendants("mvinfo") 
      select new MVData 
      { 
       VideoTitle = (string)query.Element("title"), 
       VideoYear = (string)query.Element("year"), 
       VideoSource = (string)query.Element("link"), 
       ImageSource = (string)query.Element("imgSource") 
      }; 
YouTubeMV.ItemsSource = data; 

, 그것은 열린 우리당 매개 변수가 파일 시스템 또는 절대 경로 여야한다는 오류를 보여줍니다. 다음과 같이 사용해 보았습니다.

Uri uri = new Uri("https://www.dropbox.com/s/lyf9lv03dogidb9/home.xml?dl=1"); 
XDocument document = XDocument.Load(uri); 

또한 작동하지 않습니다.

+0

합니다. 파일로 다운로드 할 필요가 없습니다. XDocument doc = XDocument.Load ("https://www.dropbox.com/s/lyf9lv03dogidb9/home.xml?dl=1"); – jdweng

답변

0

XDocument.Load()은 http 셸 URI를 사용하지 않으며 파일 액세스에 사용됩니다.

XDocument.Load("C:/test.xml"); 여기서 C:/test.xml은 XML 파일의 경로입니다. 파일에 액세스하기 전에 파일을 만들어야합니다. 당신이 스트림에서 XML을 만들려면

, 여기 좀 걸릴 수 있습니다 : 너무 간단한 XDocument Load - cannot open