Ejemplo n.º 1
0
        private async void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            var file = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("CXmlCopy.xml", Windows.Storage.CreationCollisionOption.GenerateUniqueName);

            await doc.SaveToFileAsync(file);

            RichEditBoxSetMsg(ShowXMLResult, "Save to \"" + file.Path + "\" successfully.", true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This is the click handler for the 'Scenario2BtnSave' button.
        /// This function is to save the new xml in which hot products are marked to a file.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Scenario2BtnSave_Click(object sender, RoutedEventArgs e)
        {
            String xml;

            scenario2Result.Document.GetText(Windows.UI.Text.TextGetOptions.None, out xml);

            var doc = new Windows.Data.Xml.Dom.XmlDocument();

            doc.LoadXml(xml);

            // save xml to a file
            var file = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("HotProducts.xml", Windows.Storage.CreationCollisionOption.GenerateUniqueName);

            await doc.SaveToFileAsync(file);

            Scenario.RichEditBoxSetMsg(scenario2Result, "Save to \"" + file.Path + "\" successfully.", true);

            scenario2BtnSave.IsEnabled = false;
        }
Ejemplo n.º 3
0
        public static async Task SaveOPMLFile(StorageFile libraryFile)
        {
            var document = new Windows.Data.Xml.Dom.XmlDocument();

            var rootNode = document.CreateElement("opml");

            rootNode.AddAttribute("version", "1.1");
            document.AppendChild(rootNode);

            var headNode = document.CreateElement("head");

            headNode.AddChildWithInnerText("title", "Generated by Cast");
            headNode.AddChildWithInnerText("dateCreated", DateTime.Now.ToString(CultureInfo.InvariantCulture));
            rootNode.AppendChild(headNode);

            var bodyNode = document.CreateElement("body");

            rootNode.AppendChild(bodyNode);

            foreach (var category in Categories)
            {
                var categoryNode = document.CreateElement("outline");
                bodyNode.AppendChild(categoryNode);
                categoryNode.AddAttribute("text", category);

                foreach (var podcast in Podcasts.Where(p => p.Category == category))
                {
                    var podcastNode = document.CreateElement("outline");
                    categoryNode.AppendChild(podcastNode);

                    podcastNode.AddAttribute("title", podcast.Title);
                    podcastNode.AddAttribute("type", "rss");
                    podcastNode.AddAttribute("text", podcast.FeedUrl);
                    podcastNode.AddAttribute("xmlUrl", podcast.FeedUrl);
                }
            }

            await document.SaveToFileAsync(libraryFile);
        }
        /// <summary>
        /// This is the click handler for the 'Scenario5BtnTransformToDocument' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Scenario5BtnTransformToDocument_Click(object sender, RoutedEventArgs e)
        {
            scenario5Xml.Foreground  = new SolidColorBrush(Windows.UI.Colors.White);
            scenario5Xslt.Foreground = new SolidColorBrush(Windows.UI.Colors.White);
            Scenario.RichEditBoxSetMsg(scenario5Result, "", true);

            Windows.Data.Xml.Dom.XmlDocument doc;
            Windows.Data.Xml.Dom.XmlDocument xsltDoc;
            String xml;
            String xslt;

            // Get xml content from xml input field
            scenario5Xml.Document.GetText(Windows.UI.Text.TextGetOptions.None, out xml);

            // Get xslt content from xslt input field
            scenario5Xslt.Document.GetText(Windows.UI.Text.TextGetOptions.None, out xslt);

            if (null == xml || "" == xml.Trim())
            {
                Scenario.RichEditBoxSetError(scenario5Result, "Source XML can't be empty");
                return;
            }

            if (null == xslt || "" == xslt.Trim())
            {
                Scenario.RichEditBoxSetError(scenario5Result, "XSL content can't be empty");
                return;
            }

            try
            {
                // Load xml content
                doc = new Windows.Data.Xml.Dom.XmlDocument();
                doc.LoadXml(xml);
            }
            catch (Exception exp)
            {
                scenario5Xml.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);
                Scenario.RichEditBoxSetError(scenario5Result, exp.Message);
                return;
            }

            try
            {
                // Load xslt content
                xsltDoc = new Windows.Data.Xml.Dom.XmlDocument();
                xsltDoc.LoadXml(xslt);
            }
            catch (Exception exp)
            {
                scenario5Xslt.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);
                Scenario.RichEditBoxSetError(scenario5Result, exp.Message);
                return;
            }

            try
            {
                // Transform xml according to the style sheet declaration specified in xslt file
                var xsltProcessor = new Windows.Data.Xml.Xsl.XsltProcessor(xsltDoc);
                Windows.Data.Xml.Dom.XmlDocument transformedDocument = xsltProcessor.TransformToDocument(doc);

                Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
                Windows.Storage.StorageFile   xmlFile       = await storageFolder.CreateFileAsync("transformed.xml", Windows.Storage.CreationCollisionOption.ReplaceExisting);

                await transformedDocument.SaveToFileAsync(xmlFile);

                Scenario.RichEditBoxSetMsg(scenario5Result, string.Format("The result has been saved to: \n" + xmlFile.Path), true);
            }
            catch (Exception exp)
            {
                Scenario.RichEditBoxSetError(scenario5Result, exp.Message);
                return;
            }
        }
        /// <summary>
        /// This is the click handler for the 'Scenario2BtnSave' button.
        /// This function is to save the new xml in which hot products are marked to a file.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Scenario2BtnSave_Click(object sender, RoutedEventArgs e)
        {
            String xml;
            scenario2Result.Document.GetText(Windows.UI.Text.TextGetOptions.None, out xml);

            var doc = new Windows.Data.Xml.Dom.XmlDocument();
            doc.LoadXml(xml);

            // save xml to a file
            var file = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("HotProducts.xml", Windows.Storage.CreationCollisionOption.GenerateUniqueName);
            await doc.SaveToFileAsync(file);

            Scenario.RichEditBoxSetMsg(scenario2Result, "Save to \"" + file.Path + "\" successfully.", true);

            scenario2BtnSave.IsEnabled = false;
        }