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


C# XmlDocument.SelectNodes方法代碼示例

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


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

示例1: CompleteTemplate

        public static void CompleteTemplate(XmlDocument xml, string[] text, string[] images = null, string sound = null)
        {
            XmlNodeList slots = xml.SelectNodes("descendant-or-self::image");
            int index = 0;

            if ((images != null) && (slots != null))
            {
                while ((index < images.Length) && (index < slots.Length))
                {
                    ((XmlElement)slots[index]).SetAttribute("src", images[index]);
                    index++;
                }
            }

            if (text != null)
            {
                slots = xml.SelectNodes("descendant-or-self::text");
                index = 0;

                while ((slots != null) && ((index < text.Length) && (index < slots.Length)))
                {
                    slots[index].AppendChild(xml.CreateTextNode(text[index]));
                    index++;
                }
            }

            if (!string.IsNullOrEmpty(sound))
            {
                var audioElement = xml.CreateElement("audio");
                audioElement.SetAttribute("src", sound);
                xml.DocumentElement.AppendChild(audioElement);
            }
        }
開發者ID:chrissimusokwe,項目名稱:TrainingContent,代碼行數:33,代碼來源:TemplateUtility.cs

示例2: GetFeedData

 /// <summary>
 /// Get all feed data with a structure according to <see cref="ITMUtils.NewsParsing.NewsStruct" />
 /// </summary>
 /// <returns>All feed data into a <see cref="List{Structure}"/> format</returns>
 public async static Task<ObservableCollection<NewsStruct>> GetFeedData()
 {
     ObservableCollection<NewsStruct> result = new ObservableCollection<NewsStruct>();
     HttpClient client = new HttpClient();
     string xml = await client.GetStringAsync(SourceUrl);
     XmlDocument xdoc = new XmlDocument();
     xdoc.LoadXml(xml);
     XmlNodeList nodes = xdoc.SelectNodes(TitlePath);
     foreach (IXmlNode item in nodes)
     {
         result.Add(new NewsStruct() { Title = item.InnerText });
     }
     Regex rgx = new Regex("src=\".+?\"");
     xdoc.LoadXml(xml);
     nodes = xdoc.SelectNodes(DescriptionPath);
     int count = 0;
     string text = string.Empty;
     foreach (IXmlNode item in nodes)
     {
         text = item.NextSibling.NextSibling.InnerText;
         result[count].ImgSource = rgx.Matches(text)[0].Value.Replace("src=\"", string.Empty).Replace("\"", string.Empty);
         result[count].Content = Regex.Replace(Regex.Replace(text, "<.*?>", string.Empty), "&.*?;", string.Empty);
         result[count].EncodedString = text;
         count++;
     }
     nodes = xdoc.SelectNodes(PublishDatePath);
     count = 0;
     foreach (IXmlNode item in nodes)
     {
         result[count].PublishDate = DateTime.Parse(item.InnerText).ToLocalTime();
         result[count].Author = "Autor: " + item.NextSibling.NextSibling.InnerText;
         count++;
     }
     return result;
 }
開發者ID:Anvyl,項目名稱:ITMoldova,代碼行數:39,代碼來源:Parser.cs

示例3: CompleteToastOrTileTemplate

    public static void CompleteToastOrTileTemplate(XmlDocument xml, string[] text, string[] images)
    {
      XmlNodeList slots = xml.SelectNodes("descendant-or-self::image");
      int index = 0;

      if (images != null)
      {
        while ((index < images.Length) && (index < slots.Length))
        {
          ((XmlElement)slots[index]).SetAttribute("src", images[index]);
          index++;
        }
      }

      if (text != null)
      {
        slots = xml.SelectNodes("descendant-or-self::text");
        index = 0;

        while ((index < text.Length) && (index < slots.Length))
        {
          slots[index].AppendChild(xml.CreateTextNode(text[index]));
          index++;
        }
      }
    }
開發者ID:chrissimusokwe,項目名稱:TrainingContent,代碼行數:26,代碼來源:NotificationTemplateHelper.cs

示例4: OnNavigatedTo

        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            rootPage = MainPage.Current;
            file = "status.xml";
            StorageFile storageFile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(file);
            XmlLoadSettings loadSettings = new XmlLoadSettings();
            loadSettings.ProhibitDtd = false;
            loadSettings.ResolveExternals = false;
            doc = await XmlDocument.LoadFromFileAsync(storageFile, loadSettings);
            try
            {
                var results = doc.SelectNodes("descendant::result");                
                int num_results = 1;
                foreach (var result in results)
                {
                    String id = results[num_results - 1].SelectSingleNode("descendant::id").FirstChild.NodeValue.ToString();
                    String status = results[num_results-1].SelectSingleNode("descendant::status").FirstChild.NodeValue.ToString();
                    listBox.Items.Add("ID: "+id+" "+ status);
                    num_results += 1;
                }
                if (num_results==1)
                    listBox.Items.Add("You don't have pending jobs.");
            }
            
            catch(Exception)
            { 
            listBox.Items.Add("You don't have pending jobs.");
            }

        }
開發者ID:MengyuanZhu,項目名稱:Pegasus,代碼行數:30,代碼來源:Pending_Result.xaml.cs

示例5: OnNavigatedTo

        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            rootPage = MainPage.Current;
            listBox.Items.Add("Index");
            StorageFile storageFile;
            file = "history.xml";
           
            
                storageFile= await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(file);
                XmlLoadSettings loadSettings = new XmlLoadSettings();
                loadSettings.ProhibitDtd = false;
                loadSettings.ResolveExternals = false;
                doc = await XmlDocument.LoadFromFileAsync(storageFile, loadSettings);
                var results = doc.SelectNodes("descendant::result");
                int num_results = 1;
                foreach (var result in results)
                {
                    listBox.Items.Add(num_results.ToString());
                    num_results += 1;
                }

                if (num_results > 1) //show the first history result
                {
                    listBox.SelectedIndex = 1;
                    select_item(0);
                }
            
          


            //rootPage.NotifyUser(doc.InnerText.ToString(), NotifyType.StatusMessage);

        }
開發者ID:MengyuanZhu,項目名稱:Pegasus,代碼行數:33,代碼來源:Previous_Result.xaml.cs

示例6: IsInFastFood

        public async Task<bool> IsInFastFood(GeoCoordinate geo)
        {
            XmlDocument doc = new XmlDocument();

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Add("Accept", "text/xml");

                var squarreSize = 0.0002;
                var url = "http://api.openstreetmap.org/api/0.6/map?bbox=" +
                          (geo.Longitude - squarreSize).ToString("G", CultureInfo.InvariantCulture) + "," +
                          (geo.Latitude - squarreSize).ToString("G", CultureInfo.InvariantCulture) + "," +
                          (geo.Longitude + squarreSize).ToString("G", CultureInfo.InvariantCulture) + "," +
                          (geo.Latitude + squarreSize).ToString("G", CultureInfo.InvariantCulture) + "&page=0";
                var uri = new Uri(url);
                HttpResponseMessage response = await client.GetAsync(uri);
                if (response.IsSuccessStatusCode)
                {
                    var s = await response.Content.ReadAsStringAsync();
                    doc.LoadXml(s);
                    var listNodeTag = doc.SelectNodes("//tag[@k='amenity'][@v='fast_food']");
                   // var listNodeTag = doc.SelectNodes("//tag[@k='bus'][@v='bus']");
                    //var busFound = s.IndexOf("bus") > 0;
                    if (listNodeTag.Count > 0)
                    {
                        return true;
                    }
                }
            }
            return false;
        }
開發者ID:Noitacinrofilac,項目名稱:Who-s-Hungry,代碼行數:32,代碼來源:FastFoodDetectorModel.cs

示例7: navigationHelper_LoadState

        /// <summary>
        /// Populates the page with content passed during navigation. Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session. The state will be null the first time a page is visited.</param>
        private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            try
            {
                StorageFile localFile = await ApplicationData.Current.LocalFolder.GetFileAsync("usersettings.xml");
                string localData = await FileIO.ReadTextAsync(localFile);

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(localData);

                XmlNodeList nodeList = xmlDoc.SelectNodes("Categories/Bill");

                foreach (IXmlNode node in nodeList)
                {
                    string type = node.Attributes[0].NodeValue.ToString();
                    string title = node.Attributes[1].NodeValue.ToString();
                    string subtitle = node.Attributes[2].NodeValue.ToString();
                    string imagePath = node.Attributes[3].NodeValue.ToString();
                    string portalUrl = node.Attributes[4].NodeValue.ToString();

                    string dueDate = node.FirstChild.InnerText;
                    string isPaid = node.LastChild.InnerText;

                    Bill bill = new Bill(title, subtitle, imagePath, portalUrl, BillType.CreditCard, isPaid == "1", Convert.ToDateTime(dueDate));
                    this.Bill.Add(bill);
                }

                this.DataContext = this.Bill;

            }
            catch (FileNotFoundException)
            {
                this.Frame.Navigate(typeof(BillCategories));
            }
        }
開發者ID:rajnx,項目名稱:winapps,代碼行數:46,代碼來源:HomePage.xaml.cs

示例8: ButtonSendNotification_Click

        private void ButtonSendNotification_Click(object sender, RoutedEventArgs e)
        {
            string xml = [email protected]"
                <tile version='3'>
                    <visual branding='nameAndLogo'>

                        <binding template='TileMedium'>
                            <text hint-wrap='true'>New tile notification</text>
                            <text hint-wrap='true' hint-style='captionSubtle'/>
                        </binding>

                        <binding template='TileWide'>
                            <text hint-wrap='true'>New tile notification</text>
                            <text hint-wrap='true' hint-style='captionSubtle'/>
                        </binding>

                        <binding template='TileLarge'>
                            <text hint-wrap='true'>New tile notification</text>
                            <text hint-wrap='true' hint-style='captionSubtle'/>
                        </binding>

                </visual>
            </tile>";

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);

            string nowTimeString = DateTime.Now.ToString();

            // Assign date/time values through XmlDocument to avoid any xml escaping issues
            foreach (XmlElement textEl in doc.SelectNodes("//text").OfType<XmlElement>())
                if (textEl.InnerText.Length == 0)
                    textEl.InnerText = nowTimeString;

            TileNotification notification = new TileNotification(doc);
            TileUpdateManager.CreateTileUpdaterForApplication().Update(notification);
        }
開發者ID:COMIsLove,項目名稱:Windows-universal-samples,代碼行數:37,代碼來源:ScenarioElement.xaml.cs

示例9: ReceiptExpired

        public static bool ReceiptExpired(string receipt)
        {
            var xml = new XmlDocument();
            xml.LoadXml(receipt);

            try
            {
                var xpath = "/Receipt/ProductReceipt/@ExpirationDate";
                var node = xml.SelectNodes(xpath).First();
                var att = node.InnerText;
                var date = DateTimeOffset.Parse(att);
                var remainingMinutea = (date - DateTime.Now).TotalMinutes;

                if (remainingMinutea < 1) return true;

                return false;
            }
            catch
            {
                return true;
            }

        }
開發者ID:modulexcite,項目名稱:windows8,代碼行數:23,代碼來源:DownloadManager.cs

示例10: GetProductReceiptFromAppReceipt

 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();
 }
開發者ID:modulexcite,項目名稱:windows8,代碼行數:26,代碼來源:DownloadManager.cs

示例11: FindInMetadata

        public static LibrelioLocalUrl FindInMetadata(LibrelioUrl url, XmlDocument xml)
        {
            if (xml == null) return null;

            string xpath = "/root/mag[url='" + url.AbsoluteUrl + "']";
            var nodes = xml.SelectNodes(xpath);

            if (nodes.Count > 0)
            {
                var index = Convert.ToInt32(nodes[0].SelectNodes("index")[0].InnerText);
                var title = nodes[0].SelectNodes("title")[0].InnerText;
                var subtitle = nodes[0].SelectNodes("subtitle")[0].InnerText;
                var path = nodes[0].SelectNodes("path")[0].InnerText;
                if (path != "ND")
                {
                    var pos = path.LastIndexOf('\\');
                    path = path.Substring(0, pos + 1);
                }
                var metadata = nodes[0].SelectNodes("metadata")[0].InnerText;
                if (metadata != "ND")
                {
                    var pos = metadata.LastIndexOf('\\');
                    metadata = metadata.Substring(pos + 1);
                }
                var u = nodes[0].SelectNodes("url")[0].InnerText;
                var rel = nodes[0].SelectNodes("relPath")[0].InnerText;
                var isd = nodes[0].SelectNodes("sampledownloaded")[0].InnerText;

                return new LibrelioLocalUrl(index, title, subtitle, path, GetFullNameFromUrl(rel), u, rel, isd.Equals("true"));
            }
            else
            {
                return null;
            }
        }
開發者ID:modulexcite,項目名稱:windows8,代碼行數:35,代碼來源:DownloadManager.cs

示例12: ReadPList

        private async Task ReadPList(XmlDocument plist)
        {
            _magazinesUrl.Clear();

            var items = plist.SelectNodes("/plist/array/dict");
            for (int i = 0; i < items.Count; i++)
            {
                var dict = items[i];
                LibrelioUrl url = null;
                string tite = "";
                string subtitle = "";

                foreach (var key in dict.SelectNodes("key"))
                {
                    if (key.InnerText == "FileName")
                    {
                        var relUrl = GetValue(key);

                        if (relUrl != "")
                            url = new LibrelioUrl(i, this._path, relUrl);
                    }
                    else if (key.InnerText == "Title")
                    {
                        tite = GetValue(key);
                    }
                    else if (key.InnerText == "Subtitle")
                    {
                        subtitle = GetValue(key);
                    }
                }

                if (url != null && tite != "")
                    url.Title = tite;
                if (url != null && subtitle != "")
                    url.Subtitle = subtitle;
                if (url != null)
                    _magazinesUrl.Add(url);
            }

            await UpdateLocalMetadataFromPLIST();
        }
開發者ID:threemind,項目名稱:windows8,代碼行數:41,代碼來源:MagazineManager.cs

示例13: GetCharacters

 public async void GetCharacters()
 {
     String url = "https://api.eveonline.com/account/Characters.xml.aspx?keyID=" + KeyID + "&vCode=" + VCode;
     String text;
     HttpClient client = new HttpClient();
     using (HttpResponseMessage response = await client.GetAsync(new Uri(url)))
     {
         response.EnsureSuccessStatusCode();
         text = await response.Content.ReadAsStringAsync();
     }
     XmlDocument doc = new XmlDocument();
     doc.LoadXml(text);
     XmlNodeList nodeList = doc.SelectNodes("/eveapi/result/rowset")[0].ChildNodes;
     for (int i = 0; i < nodeList.Count; i++)
     {
         IXmlNode temp = nodeList[i];
         if (temp.NodeName == "row")
         {
             EveApi.Characters.Add(new Character(temp));
         }
     }
 }
開發者ID:Malketh,項目名稱:PodWatcher,代碼行數:22,代碼來源:EveApi.cs

示例14: LoadEndpointDefinitions

        /// <summary>
        /// Parse the endpoint definition.  This method is only meant to be called directly for testing purposes.
        /// </summary>
        /// <param name="reader">A reader of the endpoint definitions</param>
        public static void LoadEndpointDefinitions(StreamReader reader)
        {
            if (loaded)
            {
                return;
            }

            lock (LOCK_OBJECT)
            {
                if (loaded)
                    return;

                
                var xmlDoc = new XmlDocument();
                var xmlContents = reader.ReadToEnd();
                xmlDoc.LoadXml(xmlContents);

                var xmlRegions = xmlDoc.SelectNodes("//Regions/Region");
                foreach (XmlElement xmlRegion in xmlRegions)
                {
                    var regionSystemName = xmlRegion.ChildNodes.First(x => x.NodeName == "Name").InnerText;

                    RegionEndpoint region = null;
                    // This version of the SDK doesn't have a constant yet for the new region
                    // so go ahead and add a new region that users can lookup by it's system name.
                    if (!RegionEndpoint.hashBySystemName.TryGetValue(regionSystemName, out region))
                    {
                        region = new RegionEndpoint(regionSystemName, regionSystemName);
                        RegionEndpoint.hashBySystemName[regionSystemName] = region;
                    }

                    var xmlEndpoints = xmlRegion.SelectNodes("Endpoint");
                    foreach (XmlElement xmlEndpoint in xmlEndpoints)
                    {
                        var serviceName = xmlEndpoint.ChildNodes.First(x => x.NodeName == "ServiceName").InnerText;
                        var hostname = xmlEndpoint.ChildNodes.First(x => x.NodeName == "Hostname").InnerText;

                        bool https = false;
                        if (xmlEndpoint.ChildNodes.First(x => x.NodeName == "Https") is XmlElement)
                            https = bool.Parse(xmlEndpoint.ChildNodes.First(x => x.NodeName == "Https").InnerText);

                        bool http = false;
                        if (xmlEndpoint.ChildNodes.First(x => x.NodeName == "Http") is XmlElement)
                            http = bool.Parse(xmlEndpoint.ChildNodes.First(x => x.NodeName == "Http").InnerText);

                        if (region.endpoints == null)
                            region.endpoints = new Dictionary<string, Endpoint>();

                        region.endpoints.Add(serviceName, new Endpoint(hostname, https, http));
                    }
                }

                loaded = true;
            }
        }
開發者ID:phillip-haydon,項目名稱:aws-sdk-net,代碼行數:59,代碼來源:RegionEndpoint.cs

示例15: playps

 private async void playps(object sender, RoutedEventArgs e)
 {
     // XML獲取
     string address = "http://dict-co.iciba.com/api/dictionary.php?w=";
     address += AddWordDisplay.Text;
     string result;
     if (address.Length == 0) return;
     else
     {
         try
         {
             HttpResponseMessage response = await httpclient.GetAsync(address);
             response.EnsureSuccessStatusCode();
             //AddPsDisplay.Text = response.StatusCode + " " + response.ReasonPhrase;
             result = await response.Content.ReadAsStringAsync();
             //AddExplainDisplay.Text = result;
         }
         catch (HttpRequestException hre)
         {
             AddExplainDisplay.Text = "Error1" + hre.ToString();
             return;
         }
         catch (Exception ex)
         {
             AddExplainDisplay.Text = "Error1" + ex.ToString();
             return;
         }
     }
     //XML解析
     string node;
     if(result.Length!=0)
     {
         try
         {
             XmlDocument xmler = new XmlDocument();
             xmler.LoadXml(result);
             XmlNodeList nodelist;
             nodelist = xmler.SelectNodes("/dict");
             node= nodelist[0].SelectSingleNode("pron").InnerText;
         }
         catch
         {
             return ;
         }
     }
     else return ;
     //AddPsDisplay.Text = node;
     //Download
     StorageFile destination = await KnownFolders.DocumentsLibrary.CreateFileAsync("TempVoice.mp3", CreationCollisionOption.ReplaceExisting);
     if (node.Length != 0)
     {
         try
         {
             Uri url = new Uri(node.Trim());
             BackgroundDownloader downloader = new BackgroundDownloader();
             DownloadOperation load = downloader.CreateDownload(url, destination);
             await load.StartAsync();
         }
         catch
         {
             return ;
         }
     }
     else return ;
     //play
     if (destination != null)
     {
         try
         {
             var stream=await destination.OpenAsync(Windows.Storage.FileAccessMode.Read);
             outputmedia.SetSource(stream,destination.ContentType);
             outputmedia.AutoPlay=true;
         }
         catch
         {
             return ;
         }
     }
     else return ;
 }
開發者ID:neveralso,項目名稱:Word,代碼行數:80,代碼來源:AddPage.xaml.cs


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