当前位置: 首页>>代码示例>>C#>>正文


C# XmlDocument.SelectNodes方法代码示例

本文整理汇总了C#中System.Xml.XmlDocument.SelectNodes方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.SelectNodes方法的具体用法?C# XmlDocument.SelectNodes怎么用?C# XmlDocument.SelectNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.XmlDocument的用法示例。


在下文中一共展示了XmlDocument.SelectNodes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadPlayerGame

    public void LoadPlayerGame(String gamePage)
    {
        DateTime gameDate = DateTime.MinValue;

        String HTML = GetPageHTML(gamePage);

        //lets get it into XML to make it easier to read
        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
        doc.LoadXml(HTML);

        //get the game date
        System.Xml.XmlNodeList nodes = doc.SelectNodes("/html/body/table/tr/td/table/tr/td/table/tr/td/table[@id='GameInfo']");
        if (nodes.Count == 0)
            nodes = doc.SelectNodes("/XMLFile/html/body/table/tr/td/table/tr/td/table/tr/td/table[@id='GameInfo']");
        foreach (System.Xml.XmlNode node in nodes)
        {
            String dateString = node.ChildNodes[3].ChildNodes[0].InnerText;
            gameDate = Convert.ToDateTime(dateString);
        }

        nodes = doc.SelectNodes("/html/body/table/tr/td/table/tr/td");
        if (nodes.Count == 0)
           nodes = doc.SelectNodes("/XMLFile/html/body/table/tr/td/table/tr/td");
        foreach (System.Xml.XmlNode node in nodes)
        {
            if (node.InnerText.Trim() == "COLORADO AVALANCHE")
            {
                RecordPlayerGamesFromTeamTable(node.ParentNode.ParentNode, gameDate, gamePage);
                break;
            }
        }
    }
开发者ID:Aphramzo,项目名称:AnAvalancheOfStats,代码行数:32,代码来源:Loader.cs

示例2: initialize

        public void initialize()
        {
            string startupPath = System.IO.Directory.GetCurrentDirectory();
            XmlDocument doc = new XmlDocument();

            try
            {
                //Get the credentials from the CredentialsToUse.xml file it is in <project>/bin/Debug folder
                doc.Load(startupPath + "../../../CredentialsToUse.xml");
                email = doc.SelectNodes("//email").Item(0).InnerText;
                password = doc.SelectNodes("//password").Item(0).InnerText;
            }

            catch (FileNotFoundException ex) {
                Console.WriteLine(ex.Message + "\n File with credentials wasn't found! Assign variables explicitly");
            }

            catch (TypeLoadException ex)
            {
                Console.WriteLine(ex.Message + "\n File with credentials wasn't load! Wrong format? Assign variables explicitly");
            }

            if (String.IsNullOrWhiteSpace(email) || String.IsNullOrWhiteSpace(password))
            {
                //If you don't use an xml file assign your data to varibles email and password expilicitly
                email = "enter email";
                password = "enter password";
            }

            CustomMethods.webDriver = new FirefoxDriver();
        }
开发者ID:Pohordn,项目名称:TestPageObjectFramework,代码行数:31,代码来源:FromTheTaskTest.cs

示例3: Deserialize

 private void Deserialize(string configXml)
 {
     if (!String.IsNullOrEmpty(configXml))
     {
         var xmlDoc = new XmlDocument();
         xmlDoc.LoadXml(configXml);
         foreach (XmlElement xmlItem in xmlDoc.SelectNodes("/EventQueueConfig/PublishedEvents/Event"))
         {
             var oPublishedEvent = new PublishedEvent();
             oPublishedEvent.EventName = xmlItem.SelectSingleNode("EventName").InnerText;
             oPublishedEvent.Subscribers = xmlItem.SelectSingleNode("Subscribers").InnerText;
             PublishedEvents.Add(oPublishedEvent.EventName, oPublishedEvent);
         }
         foreach (XmlElement xmlItem in xmlDoc.SelectNodes("/EventQueueConfig/EventQueueSubscribers/Subscriber"))
         {
             var oSubscriberInfo = new SubscriberInfo();
             oSubscriberInfo.ID = xmlItem.SelectSingleNode("ID").InnerText;
             oSubscriberInfo.Name = xmlItem.SelectSingleNode("Name").InnerText;
             oSubscriberInfo.Address = xmlItem.SelectSingleNode("Address").InnerText;
             oSubscriberInfo.Description = xmlItem.SelectSingleNode("Description").InnerText;
             oSubscriberInfo.PrivateKey = xmlItem.SelectSingleNode("PrivateKey").InnerText;
             EventQueueSubscribers.Add(oSubscriberInfo.ID, oSubscriberInfo);
         }
     }
 }
开发者ID:rut5949,项目名称:Dnn.Platform,代码行数:25,代码来源:EventQueueConfiguration.cs

示例4: changelogDocument

		/// <summary>
		/// Initialisiert eine neue Instanz der <see cref="changelogDocument"/>-Klasse.
		/// </summary>
		/// <param name="changelogXml"></param>
		public changelogDocument(XmlDocument changelogXml) {
#pragma warning disable
			changelogItems = new List<changelogDocumentItem>();
			rawChangelog = changelogXml;

			XmlNodeList changeNodes = changelogXml.SelectNodes("updateSystemDotNet.Changelog/Items/Item");

			if (changeNodes.Count > 0)
				germanChanges = changeNodes[0].SelectSingleNode("Change").InnerText;
			if (changeNodes.Count > 1)
				englishChanges = changeNodes[1].SelectSingleNode("Change").InnerText;

			foreach (XmlNode node in changelogXml.SelectNodes("updateSystemDotNet.Changelog/Items/Item")) {
				try {
					changelogItems.Add(new changelogDocumentItem(
					                   	node.SelectSingleNode("Developer").InnerText,
					                   	node.SelectSingleNode("Type").InnerText,
					                   	node.SelectSingleNode("Language").InnerText,
					                   	node.SelectSingleNode("Change").InnerText
					                   	));
#pragma warning enable
				}
				catch (NullReferenceException) {
				}
			}
		}
开发者ID:Taipi88,项目名称:updateSystem.NET,代码行数:30,代码来源:changelogDocument.cs

示例5: getCombinacionGanadora

        public Combinacion getCombinacionGanadora()
        {
            Combinacion combinacionGanadora = new Combinacion();
            combinacionGanadora.Ganadora = true;

            if (cargarXML())
            {
                documento = new XmlDocument();
                documento.Load(fichero);
                raiz = documento.DocumentElement;

                XmlNodeList nodesNumeros = documento.SelectNodes("Juego/CombinacionGanadora/Resultado[@numero]");
                foreach (XmlNode nodo in nodesNumeros)
                {
                    combinacionGanadora.Numeros.Add(Int32.Parse(nodo.Attributes["numero"].Value));
                }
                XmlNodeList nodesEstrellas = documento.SelectNodes("Juego/CombinacionGanadora/Resultado[@estrella]");

                foreach (XmlNode nodo in nodesEstrellas)
                {
                    combinacionGanadora.Estrellas.Add(Int32.Parse(nodo.Attributes["estrella"].Value));
                }

            }
            else
            {
                return null;
            }

            return combinacionGanadora;
        }
开发者ID:Maldercito,项目名称:adat,代码行数:31,代码来源:1448612659$FicheroXML.cs

示例6: Backup

        protected void Backup()
        {
            Dictionary<string, string> elements = new Dictionary<string, string>();
            elements.Add("Value1", "new_value1");

            //Word app = new Word(@"C:\Users\Derice\Desktop\abc.xml");

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(@"C:\Users\Derice\Desktop\abc.xml");

            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDoc.NameTable);
            namespaceManager.AddNamespace("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");

            XmlNodeList nodeList = xmlDoc.SelectNodes("//w:tbl/w:tr/w:tc/w:p/w:r/w:t[text()='Value4']", namespaceManager);
            XmlNodeList nodeBookmark = xmlDoc.SelectNodes("//w:tbl/w:tr/w:tc/w:p/w:bookmarkStart[@w:name='tblTest']", namespaceManager);
            if (nodeBookmark.Count == 1) Console.WriteLine("Huat ar.."); Console.Read();
            if (nodeList.Count == 1)
            {
                XmlNode trNode = nodeList[0].ParentNode.ParentNode.ParentNode.ParentNode;
                XmlNode tblNode = trNode.ParentNode;
                XmlNode cloneNode = trNode.Clone();
                cloneNode.InnerXml = cloneNode.InnerXml.Replace("Value4", "new_Value4");
                tblNode.InsertBefore(cloneNode, tblNode.LastChild);
                xmlDoc.Save(@"C:\Users\Derice\Desktop\temp.xml");
            }
        }
开发者ID:d3ric3,项目名称:derice,代码行数:26,代码来源:Program.cs

示例7: getCombinacionGanadora

        public Combinacion getCombinacionGanadora()
        {
            Combinacion combinacionGanadora = new Combinacion();
            combinacionGanadora.Ganadora = true;

            if (cargarXML())
            {
                documento = new XmlDocument();
                documento.Load(fichero);
                raiz = documento.DocumentElement;

               // string busqueda = "Juego/CombinacionGanadora/Resultado[@id=\"1\"]";
                //XmlNode valor1 = documento.SelectSingleNode("Juego/CombinacionGanadora/Resultado[@id=\"1\"]");
                //combinacionGanadora.Numero1 = valor1.Attributes["numero"].Value;
                // XmlNode valor2 = documento.SelectSingleNode("Juego/CombinacionGanadora/Resultado[@id=\"2\"]");

                XmlNodeList nodesNumeros = documento.SelectNodes("Juego/CombinacionGanadora/Resultado[@numero]");
                foreach (XmlNode nodo in nodesNumeros)
                {
                    combinacionGanadora.Numeros.Add(Int32.Parse(nodo.Attributes["numero"].Value));
                }
                XmlNodeList nodesEstrellas = documento.SelectNodes("Juego/CombinacionGanadora/Resultado[@estrella]");



            }
            else
            {
                return null;
            }

            return combinacionGanadora;
        }
开发者ID:Maldercito,项目名称:adat,代码行数:33,代码来源:1448612210$FicheroXML.cs

示例8: FeatureSourceDescription

        /// <summary>
        /// Initializes a new instance of the <see cref="FeatureSourceDescription"/> class.
        /// </summary>
        /// <param name="stream">The stream.</param>
        public FeatureSourceDescription(System.IO.Stream stream)
        {
            List<FeatureSchema> schemas = new List<FeatureSchema>();

            XmlDocument doc = new XmlDocument();
            doc.Load(stream);

            XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
            mgr.AddNamespace("xs", XmlNamespaces.XS); //NOXLATE
            mgr.AddNamespace("gml", XmlNamespaces.GML); //NOXLATE
            mgr.AddNamespace("fdo", XmlNamespaces.FDO); //NOXLATE

            //Assume XML configuration document
            XmlNodeList schemaNodes = doc.SelectNodes("fdo:DataStore/xs:schema", mgr); //NOXLATE
            if (schemaNodes.Count == 0) //Then assume FDO schema
                schemaNodes = doc.SelectNodes("xs:schema", mgr); //NOXLATE

            foreach (XmlNode sn in schemaNodes)
            {
                FeatureSchema fs = new FeatureSchema();
                fs.ReadXml(sn, mgr);
                schemas.Add(fs);
            }
            this.Schemas = schemas.ToArray();
        }
开发者ID:kanbang,项目名称:Colt,代码行数:29,代码来源:FeatureSourceDescription.cs

示例9: GetPingBack

 /// <summary>
 /// Gets a ping back
 /// </summary>
 /// <param name="Request">The HttpRequest for this item</param>
 /// <returns>The ping back message</returns>
 public static PingBackMessage GetPingBack(HttpRequest Request)
 {
     try
     {
         PingBackMessage TempMessage = new PingBackMessage();
         TempMessage.Source = "";
         TempMessage.Target = "";
         string RequestText = GetRequest(Request);
         if (!RequestText.Contains("<methodName>pingback.ping</methodName>"))
         {
             return TempMessage;
         }
         XmlDocument XMLDocument = new XmlDocument();
         XMLDocument.LoadXml(RequestText);
         XmlNodeList Nodes = XMLDocument.SelectNodes("methodCall/params/param/value/string");
         if (Nodes == null)
         {
             Nodes = XMLDocument.SelectNodes("methodCall/params/param/value");
         }
         if (Nodes != null)
         {
             TempMessage.Source = Nodes[0].InnerText.Trim();
             TempMessage.Target = Nodes[1].InnerText.Trim();
         }
         return TempMessage;
     }
     catch (Exception e)
     {
         throw e;
     }
 }
开发者ID:pengyancai,项目名称:cs-util,代码行数:36,代码来源:PingBack.cs

示例10: AddItem

 public XmlDocument AddItem(string templateFile, XmlNode addNode, int addPage)
 {
     XmlDocument owner = null;
     XmlDocument document2;
     try
     {
         owner = new XmlDocument();
         owner.Load(templateFile);
         XmlNodeList list = owner.SelectNodes("jobform/layout/page");
         for (int i = list.Count; i < addPage; i++)
         {
             XmlNode node = owner.SelectSingleNode("jobform/layout");
             node.AppendChild(this.createPageNode(node.OwnerDocument, 0));
             this.appendPageTitle(owner, node.ChildNodes[i]);
             list = owner.SelectNodes("jobform/layout/page");
         }
         XmlNode node1 = list[addPage - 1];
         node1.InnerXml = node1.InnerXml + addNode.InnerXml;
         document2 = owner;
     }
     catch (NaccsException)
     {
         throw;
     }
     catch (Exception exception)
     {
         throw new NaccsException(MessageKind.Error, 0x261, exception.Message);
     }
     return document2;
 }
开发者ID:huamanhtuyen,项目名称:VNACCS,代码行数:30,代码来源:ConvertTemplate.cs

示例11: ParseXML

        static void ParseXML(XmlDocument xmldoc)
        {
            Generator gen = new Generator();

            foreach (XmlNode node in xmldoc.SelectNodes("/GCC_XML/Enumeration"))
            {
                gen.InsertNode(xmldoc, node, null);
            }

            foreach (XmlNode node in xmldoc.SelectNodes("/GCC_XML/Struct"))
            {
                gen.InsertNode(xmldoc, node, null);
            }

            foreach (XmlNode node in xmldoc.SelectNodes("/GCC_XML/Class"))
            {
                gen.InsertNode(xmldoc, node, null);
            }

            foreach (XmlNode node in xmldoc.SelectNodes("/GCC_XML/File"))
            {
                gen.InsertNode(xmldoc, node, null);
            }

            gen.WriteToFile(null);
        }
开发者ID:AluminumKen,项目名称:hl2sb-src,代码行数:26,代码来源:Program.cs

示例12: TestExecuter

		public TestExecuter(string configFile)
		{
			Logger logger = new Logger();
			this.context = new Context(this, logger);
			XmlDocument testConfig = new XmlDocument();
			testConfig.Load(configFile);

			// Get test name...
			XmlNode nameNode = testConfig.SelectSingleNode("/TestCase/@testName");
			if ( null != nameNode )
			{
				this.testName = nameNode.Value;
			}

			logger.WriteLine(" ");
			logger.WriteLine(new string('-', 79));
			logger.WriteLine("                                   S T A R T" );
			logger.WriteLine( " " );
			string userName = GetUserName();
			logger.WriteLine(string.Format("Test: {0} started @ {1} by {2}", this.testName, GetNow(), userName));
			logger.WriteLine(new string('-', 79));

			// Get test setup / execution / teardown steps
			this.setupSteps = testConfig.SelectNodes("/TestCase/TestSetup/*");
			this.executeSteps = testConfig.SelectNodes("/TestCase/TestExecution/*");
			this.teardownSteps = testConfig.SelectNodes("/TestCase/TestCleanup/*");

			this.logger = logger;
		}
开发者ID:RobBowman,项目名称:BizUnit,代码行数:29,代码来源:TestExecuter.cs

示例13: BuildFomXmlString

        /// <summary>
        /// Builds an <see cref="XmlLocalizationDictionary"/> from given xml string.
        /// </summary>
        /// <param name="xmlString">XML string</param>
        internal static XmlLocalizationDictionary BuildFomXmlString(string xmlString)
        {
            var settingsXmlDoc = new XmlDocument();
            settingsXmlDoc.LoadXml(xmlString);

            var localizationDictionaryNode = settingsXmlDoc.SelectNodes("/localizationDictionary");
            if (localizationDictionaryNode == null || localizationDictionaryNode.Count <= 0)
            {
                throw new AbpException("A Localization Xml must include localizationDictionary as root node.");
            }

            var dictionary = new XmlLocalizationDictionary(new CultureInfo(localizationDictionaryNode[0].GetAttributeValue("culture")));

            var textNodes = settingsXmlDoc.SelectNodes("/localizationDictionary/texts/text");
            if (textNodes != null)
            {
                foreach (XmlNode node in textNodes)
                {
                    var name = node.GetAttributeValue("name");
                    var value = node.GetAttributeValue("value");
                    if (string.IsNullOrEmpty(name))
                    {
                        throw new AbpException("name attribute of a text is empty in given xml string.");
                    }

                    dictionary[name] = value;
                }
            }

            return dictionary;
        }
开发者ID:JackBao,项目名称:aspnetboilerplate,代码行数:35,代码来源:XmlLocalizationDictionary.cs

示例14: Main

        //Write a program that extracts all different artists, which are found in the catalog.xml.
        //For each artist print the number of albums in the catalogue.
        //Use the XPath and a Dictionary<string,int> (use the artist name as key and the number of albums as value in the dictionary).
        static void Main()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("../../../catalog.xml");
            var artists = new Dictionary<string, int>();
            string xPathQueryArtists = "/albums/album/artist";
            string xPathQueryAlbums = "/albums/album/name";
            XmlNodeList artistsList = doc.SelectNodes(xPathQueryArtists);
            XmlNodeList albumList = doc.SelectNodes(xPathQueryAlbums);
            foreach (XmlNode artist in artistsList)
            {
                string artistName = artist.InnerText;
                int numOfAlbums = albumList
                    .Cast<XmlNode>()
                    .Where(a => a.NextSibling.InnerText == artistName)
                    .Count();
                if (!artists.ContainsKey(artistName))
                {
                    artists.Add(artistName, numOfAlbums);
                }
            }

            foreach (var artist in artists)
            {
                Console.WriteLine("Artist: {0}; number of albums: {1}", artist.Key, artist.Value);
            }
        }
开发者ID:dpetrova,项目名称:Database-Applications,代码行数:30,代码来源:Program.cs

示例15: FromFile

 public static XImage FromFile(string filename)
 {
     XImage x = new XImage();
     try
     {
         XmlDocument doc = new XmlDocument();
         doc.Load(filename);
         XmlNodeList colorList = doc.SelectNodes("/Image/Point/Color");
         XmlNodeList xList = doc.SelectNodes("/Image/Point/X");
         XmlNodeList yList = doc.SelectNodes("/Image/Point/Y");
         
         for (int i = 0; i < xList.Count; i++)
         {
             IExtendFramework.Drawing.XPoint p = new IExtendFramework.Drawing.XPoint(
                 int.Parse(xList[i].InnerText),
                 int.Parse(yList[i].InnerText),
                 new Pen(Color.FromName(colorList[i].InnerText))
                );
             //MessageBox.Show(p.ToString());
             x.Points.Add(p);
         }
     }
     catch(Exception e)
     {
         throw e;
     }
     return x;
 }
开发者ID:mlnlover11,项目名称:IExtendFramework,代码行数:28,代码来源:XImage.cs


注:本文中的System.Xml.XmlDocument.SelectNodes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。