static string ToXmlString( string input ) { var document = new XmlDocument(); document.LoadXml( input.Trim(), new XmlLoadSettings { ElementContentWhiteSpace = false } ); var result = document.GetXml(); return result; }
private void UpdateTileWithTextWithStringManipulation_Click(object sender, RoutedEventArgs e) { // create a string with the tile template xml string tileXmlString = "<tile>" + "<visual>" + "<binding template='TileWideText03'>" + "<text id='1'>Hello World! My very own tile notification</text>" + "</binding>" + "<binding template='TileSquareText04'>" + "<text id='1'>Hello World! My very own tile notification</text>" + "</binding>" + "</visual>" + "</tile>"; // create a DOM Windows.Data.Xml.Dom.XmlDocument tileDOM = new Windows.Data.Xml.Dom.XmlDocument(); // load the xml string into the DOM, catching any invalid xml characters tileDOM.LoadXml(tileXmlString); // create a tile notification TileNotification tile = new TileNotification(tileDOM); // send the notification to the app's application tile TileUpdateManager.CreateTileUpdaterForApplication().Update(tile); OutputTextBlock.Text = MainPage.PrettyPrint(tileDOM.GetXml()); }
public static SyndicationFeed Parse(string xml) { //DtdProcessing = DtdProcessing.Ignore is needed for some feeds (e.g. http://www.dotnetrocks.com/feed.aspx) var feed = new SyndicationFeed(); var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); feed.Load(xmlDoc.GetXml()); //feed.Load(reader.ReadContentAsString()); return feed; }
public static XDocument ToXDocument(this DomXmlDocument xmlDocument) { using (var memStream = new MemoryStream()) { using (var w = XmlWriter.Create(memStream)) { w.WriteRaw(xmlDocument.GetXml()); } memStream.Seek(0, SeekOrigin.Begin); using (var r = XmlReader.Create(memStream)) { return(XDocument.Load(r)); } } }
private async Task DumpTemplate(object type, XmlDocument template) { string filename = string.Format("{0}.xml", type); StorageFile file = null; try { file = await ApplicationData.Current.LocalFolder.GetFileAsync(filename); } catch { } if (file == null) file = await ApplicationData.Current.LocalFolder.CreateFileAsync(filename); // save... Debug.WriteLine(string.Format("Saving '{0}'...", filename)); FileIO.WriteTextAsync(file, template.GetXml()); }
private ToastNotification CreateToast(XmlDocument content) { Debug.WriteLine(content.GetXml()); var toast = new ToastNotification(content); if (ExpirationTime.HasValue) { toast.ExpirationTime = ExpirationTime; } toast.Activated += OnActivated; toast.Dismissed += OnDismissed; toast.Failed += OnFailed; return toast; }
public static string GetProductReceiptFromAppReceipt(string productId, string appReceipt) { var xml = new XmlDocument(); xml.LoadXml(appReceipt); try { var xpath = "/Receipt/ProductReceipt[@ProductId='" + productId + "']"; var productReceipt = xml.SelectNodes(xpath).First(); if (productReceipt == null) return ""; var root = xml.SelectNodes("/Receipt").First(); while (root.ChildNodes.Last() != productReceipt) { root.RemoveChild(root.ChildNodes.Last()); } while (root.ChildNodes.First() != productReceipt) { root.RemoveChild(root.ChildNodes.First()); } } catch { return ""; } return xml.GetXml(); }
private async void GenerateGpx(LondonBicycles.Data.Models.Point myLocation, LondonBicycles.Data.Models.Point destination) { if (this.route.RoutePoints.Count() > 0) { XmlDocument doc = new XmlDocument(); XmlElement gpx = doc.CreateElement("gpx"); gpx.SetAttribute("xmlns", "http://www.topografix.com/GPX/1/1"); gpx.SetAttribute("version", "1.1"); gpx.SetAttribute("creator", "London Bicycles"); gpx.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); XmlElement wptStart = doc.CreateElement("wpt"); wptStart.SetAttribute("lon", myLocation.Longitude.ToString()); wptStart.SetAttribute("lat", myLocation.Latitude.ToString()); gpx.AppendChild(wptStart); XmlElement wptEnd = doc.CreateElement("wpt"); wptEnd.SetAttribute("lon", destination.Longitude.ToString()); wptEnd.SetAttribute("lat", destination.Latitude.ToString()); gpx.AppendChild(wptEnd); XmlElement track = doc.CreateElement("trk"); XmlElement trackSegment = doc.CreateElement("trkseg"); foreach (var point in this.route.RoutePoints) { XmlElement trackPoint = doc.CreateElement("trkpt"); XmlAttribute lonTrack = doc.CreateAttribute("lon"); lonTrack.Value = point.Longitude.ToString(); XmlAttribute latTrack = doc.CreateAttribute("lat"); latTrack.Value = point.Latitude.ToString(); trackPoint.SetAttribute("lon", point.Longitude.ToString()); trackPoint.SetAttribute("lat", point.Latitude.ToString()); trackSegment.AppendChild(trackPoint); } track.AppendChild(trackSegment); gpx.AppendChild(track); doc.AppendChild(gpx); string text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; text += doc.GetXml(); StorageFolder sf = Windows.Storage.ApplicationData.Current.RoamingFolder; StorageFile file = await sf.CreateFileAsync("route.gpx", CreationCollisionOption.ReplaceExisting); Windows.Storage.FileIO.WriteTextAsync(file, text); this.gpxFile = file; this.RegisterForShare(); } }
private async Task GetHtmlContent(DataPackage requestData, Empresa empresa, Item item) { var xml = new XmlDocument(); var body = xml.CreateElement("DIV"); xml.AppendChild(body); //Dados da empresa string Telefones = Utils.GetTelefoneNumeros(empresa.Telefones); string empresaShareText = empresa.ShareTexto.Replace("#TELEFONE#", Telefones).Replace("#URL#", empresa.Website); var empresaData = xml.CreateElement("P"); empresaData.InnerText = empresaShareText; body.AppendChild(empresaData); body.AppendChild(xml.CreateElement("HR")); //Dados do Item compartilhado var Image = xml.CreateElement("IMG"); Image.SetAttribute("SRC", new Uri(_baseUri, item.ImageUrl).ToString()); body.AppendChild(Image); var Itemtipo = xml.CreateElement("H2"); Itemtipo.InnerText = item.SubTitulo; var breakline = xml.CreateElement("BR"); Itemtipo.AppendChild(breakline); var bold = xml.CreateElement("b"); bold.InnerText = string.Format("R$ {0}", item.Valor); Itemtipo.AppendChild(bold); body.AppendChild(Itemtipo); var ImageDescription = xml.CreateElement("P"); ImageDescription.InnerText = item.Descricao; body.AppendChild(ImageDescription); var localImage = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(item.ImageUrl.Replace("/", "\\")); requestData.SetHtmlFormat(HtmlFormatHelper.CreateHtmlFormat(xml.GetXml())); requestData.ResourceMap[new Uri(_baseUri, item.ImageUrl).ToString()] = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(localImage); }
/// <summary> /// Update the text in the SSML field for the language to match the chosen language /// </summary> /// <remarks> /// SSML language takes priority over the chosen language used by the synthesier. /// so when changing voices, we need to update the SSML language as well. /// </remarks> private void UpdateSSMLText() { try { string text = this.tbData.Text; string language = this.synthesizer.Voice.Language; XmlDocument doc = new XmlDocument(); doc.LoadXml(text); var LangAttribute = doc.DocumentElement.GetAttributeNode("xml:lang"); LangAttribute.InnerText = language; this.tbData.Text = doc.GetXml(); } catch { // this can fail if the user is in the process of editing the XML // in this case, we simply don't update the SSML language, but don't throw a failure } }
/// <summary> /// Update the text in the SSML field to match the language of the chosen synthesizer voice. /// </summary> /// <remarks> /// SSML language takes priority over the chosen synthesizer language. /// Thus, when changing voices, we need to update the SSML language to match. /// </remarks> private void UpdateSSMLText() { try { string text = textToSynthesize.Text; string language = synthesizer.Voice.Language; XmlDocument doc = new XmlDocument(); doc.LoadXml(text); var LangAttribute = doc.DocumentElement.GetAttributeNode("xml:lang"); LangAttribute.InnerText = language; textToSynthesize.Text = doc.GetXml(); } catch { // This can fail if the user is in the process of editing the XML. // In this case, we don't update the SSML language but also don't throw a failure. } }
void DisplayTextToastWithStringManipulation(ToastTemplateType templateType) { string toastXmlString = String.Empty; if (templateType == ToastTemplateType.ToastText01) { toastXmlString = "<toast>" + "<visual version='1'>" + "<binding template='ToastText01'>" + "<text id='1'>Body text that wraps over three lines</text>" + "</binding>" + "</visual>" + "</toast>"; } else if (templateType == ToastTemplateType.ToastText02) { toastXmlString = "<toast>" + "<visual version='1'>" + "<binding template='ToastText02'>" + "<text id='1'>Heading text</text>" + "<text id='2'>Body text that wraps over two lines</text>" + "</binding>" + "</visual>" + "</toast>"; } else if (templateType == ToastTemplateType.ToastText03) { toastXmlString = "<toast>" + "<visual version='1'>" + "<binding template='ToastText03'>" + "<text id='1'>Heading text that is very long and wraps over two lines</text>" + "<text id='2'>Body text</text>" + "</binding>" + "</visual>" + "</toast>"; } else if (templateType == ToastTemplateType.ToastText04) { toastXmlString = "<toast>" + "<visual version='1'>" + "<binding template='ToastText04'>" + "<text id='1'>Heading text</text>" + "<text id='2'>First body text</text>" + "<text id='3'>Second body text</text>" + "</binding>" + "</visual>" + "</toast>"; } Windows.Data.Xml.Dom.XmlDocument toastDOM = new Windows.Data.Xml.Dom.XmlDocument(); toastDOM.LoadXml(toastXmlString); rootPage.NotifyUser(toastDOM.GetXml(), NotifyType.StatusMessage); // Create a toast, then create a ToastNotifier object to show // the toast ToastNotification toast = new ToastNotification(toastDOM); // If you have other applications in your package, you can specify the AppId of // the app to create a ToastNotifier for that application ToastNotificationManager.CreateToastNotifier().Show(toast); }
public async Task checkFileSystem() { StorageFile file; bool there = true; try { file = await ApplicationData.Current.LocalFolder.GetFileAsync("logdata.xml"); } catch (FileNotFoundException) { Debug.WriteLine("No file found"); there = false; } if (there == false) { //Debug.WriteLine("Creating File"); XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("LOG"); doc.AppendChild(root); file = await ApplicationData.Current.LocalFolder.CreateFileAsync("logdata.xml"); await FileIO.WriteTextAsync(file, doc.GetXml()); Debug.WriteLine("Done creating file."); //await doc.SaveToFileAsync(st); } }
public void WriteXmlDocument(XmlDocument document) { this.writeAmf3Type(Amf3Type.XmlDocument); var xml = document.GetXml(); this.partialWriteString(xml == string.Empty ? "<>" : xml); }
public void WriteXml(XmlDocument document) { this.writeAmf3Type(Amf3Type.Xml); this.partialWriteString(document.GetXml()); }
private async void buyMag_Click(object sender, RoutedEventArgs e) { if (licenseInformation == null) return; if (!licenseInformation.ProductLicenses[product_id].IsActive) { try { // The customer doesn't own this feature, so // show the purchase dialog. var receipt = await CurrentAppSimulator.RequestProductPurchaseAsync(product_id, true); if (!licenseInformation.ProductLicenses[product_id].IsActive || receipt == "") return; await DownloadManager.StoreReceiptAsync(product_id, receipt); // the in-app purchase was successful // TEST ONLY // ================================================= var f = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"Assets\test\receipt.pmd"); var xml = new XmlDocument(); xml = await XmlDocument.LoadFromFileAsync(f); var item = xml.GetElementsByTagName("ProductReceipt")[0] as XmlElement; item.SetAttribute("ProductId", product_id); var date = new DateTimeOffset(DateTime.Now); date = date.AddMinutes(3); var str = date.ToString("u"); str = str.Replace(" ", "T"); item.SetAttribute("ExpirationDate", str); receipt = xml.GetXml(); if (DownloadManager.ReceiptExpired(receipt)) return; // ================================================= buyMag.Visibility = Windows.UI.Xaml.Visibility.Collapsed; if (Bought != null) { Bought(this, DownloadManager.GetUrl(product_id, receipt, relativePath)); this.Visibility = Windows.UI.Xaml.Visibility.Collapsed; } else { var messageDialog = new MessageDialog("Purchase successfull"); var task = messageDialog.ShowAsync().AsTask(); } } catch (Exception) { // The in-app purchase was not completed because // an error occurred. var messageDialog = new MessageDialog("Unexpected error"); var task = messageDialog.ShowAsync().AsTask(); } } else { var messageDialog = new MessageDialog("You already purchased this app"); var task = messageDialog.ShowAsync().AsTask(); } }
public static async Task StoreReceiptAsync(string productId, string receipt) { if (productId.Contains("subscritpion") && DownloadManager.ReceiptExpired(receipt)) return; var encryptedFilename = CipherEncryption(productId); var encodedFileName = Convert.ToBase64String(encryptedFilename.ToArray()); var encodedAndEscapedFilename = encodedFileName.Replace('/', '-'); // TEST ONLY // ================================================= var f = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"Assets\test\receipt.pmd"); var xml = new XmlDocument(); xml = await XmlDocument.LoadFromFileAsync(f); var item = xml.GetElementsByTagName("ProductReceipt")[0] as XmlElement; item.SetAttribute("ProductId", productId); var date = new DateTimeOffset(DateTime.Now); date = date.AddMinutes(3); var str = date.ToString("u"); str = str.Replace(" ", "T"); item.SetAttribute("ExpirationDate", str); receipt = xml.GetXml(); if (DownloadManager.ReceiptExpired(receipt)) return; // ================================================= var folder = ApplicationData.Current.RoamingFolder; if (folder == null) return; folder = await folder.CreateFolderAsync("Receipts", CreationCollisionOption.OpenIfExists); var file = await folder.CreateFileAsync(encodedAndEscapedFilename + ".pmd", CreationCollisionOption.ReplaceExisting); IBuffer buffEncrypted = CipherEncryption(receipt); var stream = await file.OpenAsync(FileAccessMode.ReadWrite); await stream.WriteAsync(buffEncrypted); await stream.FlushAsync(); stream.Dispose(); stream = null; buffEncrypted = null; file = null; ApplicationData.Current.SignalDataChanged(); //CipherDecryption(buffEncrypted); }
public void ConvertXMLDocumenttoString(XmlDocument xmlDoc) { ToastXMLContent = xmlDoc.GetXml(); var content= xmlDoc.InnerText; }
void DisplayTextToastWithStringManipulation(ToastTemplateType templateType) { string toastXmlString = String.Empty; if (templateType == ToastTemplateType.ToastText01) { toastXmlString = "<toast>" + "<visual version='1'>" + "<binding template='ToastText01'>" + "<text id='1'>Body text that wraps over three lines</text>" + "</binding>" + "</visual>" + "</toast>"; } else if (templateType == ToastTemplateType.ToastText02) { toastXmlString = "<toast>" + "<visual version='1'>" + "<binding template='ToastText02'>" + "<text id='1'>Heading text</text>" + "<text id='2'>Body text that wraps over two lines</text>" + "</binding>" + "</visual>" + "</toast>"; } else if (templateType == ToastTemplateType.ToastText03) { toastXmlString = "<toast>" + "<visual version='1'>" + "<binding template='ToastText03'>" + "<text id='1'>Heading text that is very long and wraps over two lines</text>" + "<text id='2'>Body text</text>" + "</binding>" + "</visual>" + "</toast>"; } else if (templateType == ToastTemplateType.ToastText04) { toastXmlString = "<toast>" + "<visual version='1'>" + "<binding template='ToastText04'>" + "<text id='1'>Heading text</text>" + "<text id='2'>First body text</text>" + "<text id='3'>Second body text</text>" + "</binding>" + "</visual>" + "</toast>"; } Windows.Data.Xml.Dom.XmlDocument toastDOM = new Windows.Data.Xml.Dom.XmlDocument(); toastDOM.LoadXml(toastXmlString); rootPage.NotifyUser(toastDOM.GetXml(), NotifyType.StatusMessage); // Create a toast, then create a ToastNotifier object to show // the toast ToastNotification toast = new ToastNotification(toastDOM); // If you have other applications in your package, you can specify the AppId of // the app to create a ToastNotifier for that application ToastNotificationManager.CreateToastNotifier().Show(toast); }