/// <summary> /// This is the click handler for the 'scenario3BtnBuffer' button. You would replace this with your own handler /// if you have a button or buttons on this page. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void Scenario3BtnBuffer_Click(object sender, RoutedEventArgs e) { try { // Get load settings var loadSettings = new Windows.Data.Xml.Dom.XmlLoadSettings(); if (true == scenario3RB1.IsChecked) { loadSettings.ProhibitDtd = true; // DTD is prohibited loadSettings.ResolveExternals = false; // Disable the resolve to external definitions such as external DTD } else if (true == scenario3RB2.IsChecked) { loadSettings.ProhibitDtd = false; // DTD is not prohibited loadSettings.ResolveExternals = false; // Disable the resolve to external definitions such as external DTD } else if (true == scenario3RB3.IsChecked) { loadSettings.ProhibitDtd = false; // DTD is not prohibited loadSettings.ResolveExternals = true; // Enable the resolve to external definitions such as external DTD } String xml; scenario3OriginalData.Document.GetText(Windows.UI.Text.TextGetOptions.None, out xml); // Set external dtd file path if (loadSettings.ResolveExternals == true && loadSettings.ProhibitDtd == false) { Windows.Storage.StorageFolder storageFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("loadExternaldtd"); String dtdPath = storageFolder.Path + "\\dtd.txt"; xml = xml.Replace("dtd.txt", dtdPath); } var dataWriter = new Windows.Storage.Streams.DataWriter(); dataWriter.WriteString(xml); Windows.Storage.Streams.IBuffer ibuffer = dataWriter.DetachBuffer(); var doc = new Windows.Data.Xml.Dom.XmlDocument(); doc.LoadXmlFromBuffer(ibuffer, loadSettings); Scenario.RichEditBoxSetMsg(scenario3Result, doc.GetXml(), true); } catch (Exception) { // After loadSettings.ProhibitDtd is set to true, the exception is expected as the sample XML contains DTD Scenario.RichEditBoxSetError(scenario3Result, "Error: DTD is prohibited"); } }
internal async Task <Windows.Data.Xml.Dom.XmlDocument> LoadManifestAsync(string url) { Uri uri = null; IBuffer buffer = null; try { uri = new Uri(url); } catch { #if DEBUG Logger.Log("Bad url: " + url); #endif throw new Exception("Invalid URL"); } buffer = await Downloader.DownloadBufferAsync(uri); if (buffer == null) { #if DEBUG Logger.Log("Failed to get buffer of manifest"); #endif throw new Exception("Failed to get buffer from url"); } Windows.Data.Xml.Dom.XmlDocument document = new Windows.Data.Xml.Dom.XmlDocument(); try { var bufferString = DataReader.FromBuffer(buffer).ReadString(buffer.Length); document.LoadXmlFromBuffer(buffer); } catch (Exception e) { #if DEBUG Logger.Log("Failed to load XML from buffer = " + Logger.Display(e)); #endif throw new Exception("Invalid XML file"); } return(document); }
/// <summary> /// This is the click handler for the 'scenario3BtnBuffer' button. You would replace this with your own handler /// if you have a button or buttons on this page. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void Scenario3BtnBuffer_Click(object sender, RoutedEventArgs e) { try { // Get load settings var loadSettings = new Windows.Data.Xml.Dom.XmlLoadSettings(); if (true == scenario3RB1.IsChecked) { loadSettings.ProhibitDtd = true; // DTD is prohibited loadSettings.ResolveExternals = false; // Disable the resolve to external definitions such as external DTD } else if (true == scenario3RB2.IsChecked) { loadSettings.ProhibitDtd = false; // DTD is not prohibited loadSettings.ResolveExternals = false; // Disable the resolve to external definitions such as external DTD } else if (true == scenario3RB3.IsChecked) { loadSettings.ProhibitDtd = false; // DTD is not prohibited loadSettings.ResolveExternals = true; // Enable the resolve to external definitions such as external DTD } String xml; scenario3OriginalData.Document.GetText(Windows.UI.Text.TextGetOptions.None, out xml); // Set external dtd file path if (loadSettings.ResolveExternals == true && loadSettings.ProhibitDtd == false) { Windows.Storage.StorageFolder storageFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("loadExternaldtd"); String dtdPath = storageFolder.Path + "\\dtd.txt"; xml = xml.Replace("dtd.txt", dtdPath); } var dataWriter = new Windows.Storage.Streams.DataWriter(); dataWriter.WriteString(xml); Windows.Storage.Streams.IBuffer ibuffer = dataWriter.DetachBuffer(); var doc = new Windows.Data.Xml.Dom.XmlDocument(); doc.LoadXmlFromBuffer(ibuffer, loadSettings); Scenario.RichEditBoxSetMsg(scenario3Result, doc.GetXml(), true); } catch (Exception) { // After loadSettings.ProhibitDtd is set to true, the exception is expected as the sample XML contains DTD Scenario.RichEditBoxSetError(scenario3Result, "Error: DTD is prohibited"); } }
internal async Task<Windows.Data.Xml.Dom.XmlDocument> LoadManifestAsync(string url) { Uri uri = null; IBuffer buffer = null; try { uri = new Uri(url); } catch { #if DEBUG Logger.Log("Bad url: " + url); #endif throw new Exception("Invalid URL"); } buffer = await Downloader.DownloadBufferAsync(uri); if (buffer == null) { #if DEBUG Logger.Log("Failed to get buffer of manifest"); #endif throw new Exception("Failed to get buffer from url"); } Windows.Data.Xml.Dom.XmlDocument document = new Windows.Data.Xml.Dom.XmlDocument(); try { var bufferString = DataReader.FromBuffer(buffer).ReadString(buffer.Length); document.LoadXmlFromBuffer(buffer); } catch (Exception e) { #if DEBUG Logger.Log("Failed to load XML from buffer = " + Logger.Display(e)); #endif throw new Exception("Invalid XML file"); } return document; }