當前位置: 首頁>>代碼示例>>C#>>正文


C# XmlDocument.CreateAttribute方法代碼示例

本文整理匯總了C#中Windows.Data.Xml.Dom.XmlDocument.CreateAttribute方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlDocument.CreateAttribute方法的具體用法?C# XmlDocument.CreateAttribute怎麽用?C# XmlDocument.CreateAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Windows.Data.Xml.Dom.XmlDocument的用法示例。


在下文中一共展示了XmlDocument.CreateAttribute方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SetSilent

        private static void SetSilent(bool useSound, XmlDocument toastXml)
        {
            var audio = toastXml.GetElementsByTagName("audio").FirstOrDefault();

            if (audio == null)
            {
                audio = toastXml.CreateElement("audio");
                var toastNode = ((XmlElement)toastXml.SelectSingleNode("/toast"));

                if (toastNode != null)
                {
                    toastNode.AppendChild(audio);
                }
            }

            var attribute = toastXml.CreateAttribute("silent");
            attribute.Value = (!useSound).ToString().ToLower();
            audio.Attributes.SetNamedItem(attribute);
        }
開發者ID:PlagueHO,項目名稱:toaster,代碼行數:19,代碼來源:Program.cs

示例2: GenerateGpx

        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();
            }
        }
開發者ID:stamo,項目名稱:LondonBicycles,代碼行數:57,代碼來源:DetailsViewModel.cs


注:本文中的Windows.Data.Xml.Dom.XmlDocument.CreateAttribute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。