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


C# XmlDataDocument.SelectNodes方法代碼示例

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


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

示例1: RetrieveFilterData

        public static DataTable RetrieveFilterData(string filterPath)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("Category", typeof(string)));
            dt.Columns.Add(new DataColumn("Name", typeof(string)));
            dt.Columns.Add(new DataColumn("Value", typeof(string)));

            DataSet ds = new DataSet();
            ds.ReadXml(filterPath);

            XmlDataDocument xmlDataDoc = new XmlDataDocument(ds);
            string strXPathQuery = "/root/filter";
            string category = string.Empty;
            string itemName = string.Empty;
            string itemValue = string.Empty;

            DataRow dr = null;

            foreach (XmlNode nodeDetail in xmlDataDoc.SelectNodes(strXPathQuery))
            {
                category = nodeDetail.ChildNodes[0].InnerText.ToString();
                itemName = nodeDetail.ChildNodes[1].InnerText.ToString();
                itemValue = nodeDetail.ChildNodes[2].InnerText.ToString();

                dr = dt.NewRow();

                dr["Category"] = category;
                dr["Name"] = itemName;
                dr["Value"] = itemValue;

                dt.Rows.Add(dr);
            }

            return dt;
        }
開發者ID:navkar,項目名稱:BizTalkControlCenter,代碼行數:35,代碼來源:BCCUIHelper.cs

示例2: button5_Click

		private void button5_Click(object sender, EventArgs e)
		{
            XmlDocument doc = new XmlDocument();
			//create a dataset
			DataSet ds = new DataSet("XMLProducts");
			//connect to the northwind database and
			//select all of the rows from products table and from suppliers table
			//make sure you connect string matches you server configuration

			SqlConnection conn = new SqlConnection(_connectString);

            SqlDataAdapter daProduct = new SqlDataAdapter("SELECT Name, StandardCost, ProductCategoryID FROM SalesLT.Product", conn);
			SqlDataAdapter daCategory = new SqlDataAdapter("SELECT ProductCategoryID, Name from SalesLT.ProductCategory", conn);
			//Fill DataSet from both SqlAdapters
			daProduct.Fill(ds, "Products");
			daCategory.Fill(ds, "Categories");
			//Add the relation
			ds.Relations.Add(ds.Tables["Categories"].Columns["ProductCategoryID"],
				ds.Tables["Products"].Columns["ProductCategoryID"]);
			//Write the Xml to a file so we can look at it later
			ds.WriteXml("Products.xml", XmlWriteMode.WriteSchema);
			//load data into grid
			dataGridView1.DataSource = ds.Tables[0];
			//create the XmlDataDocument
			doc = new XmlDataDocument(ds);
			//Select the productname elements and load them in the grid
			XmlNodeList nodeLst = doc.SelectNodes("//XMLProducts/Products");
            textBox1.Text = "";
            foreach (XmlNode node in nodeLst)
            {
                textBox1.Text += node.InnerXml + "\r\n";
            }
		}
開發者ID:ChegnduJackli,項目名稱:Projects,代碼行數:33,代碼來源:frmADOXML.cs

示例3: Main

        static void Main(string[] args)
        {
            if (!Directory.Exists(@".\Reports"))
            {
                Directory.CreateDirectory(@".\Reports");
            }
            File.Copy(resultFileName, @".\Reports\TestResult.xml", true);

            double totalTestcases;
            double totalPassed;
            double totalFailed;
            double totalError;
            XmlDataDocument xmldoc = new XmlDataDocument();
            XmlNodeList xmlResultsnode;
            errors = new List<ErrorItem>();
            sucess = new List<SuccessItem>();
            try
            {
                //Analize test results file
                FileStream fstream = new FileStream(resultFileName, FileMode.Open, FileAccess.Read);
                try
                {
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(fstream);
                    LoadTestResults(xmlDoc.DocumentElement);
                }
                finally
                {
                    fstream.Close();
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error occur: ");
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.WriteLine(ex.Message);
                Console.Beep();
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine("");
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey(true);
                return;
            }
            CreatePlayBack playback = new CreatePlayBack(Directory.GetCurrentDirectory() + @"\Reports\");
            playback.CreateReports();
            FileStream fs = new FileStream(resultFileName, FileMode.Open, FileAccess.Read);
            xmldoc.Load(fs);
            xmlResultsnode = xmldoc.SelectNodes("//test-results[contains(@ignored,'0')]");
            totalTestcases = Convert.ToDouble(xmlResultsnode[0].Attributes["total"].Value);
            totalFailed = Convert.ToDouble(xmlResultsnode[0].Attributes["failures"].Value);
            totalError = Convert.ToDouble(xmlResultsnode[0].Attributes["errors"].Value);
            totalPassed = totalTestcases - totalFailed - totalError;
            totalFailed = totalFailed + totalError;

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<Html>");
            CreateHtmlHeader(sb);
            sb.AppendLine("<body background=\"./img/background.jpg\">");
            CreateHeadline(sb);
            CreateSummary(sb, "TCD Automation", totalTestcases, totalPassed, totalFailed);
            CreateBody(sb, sucess);
            CreateChartScript(sb, totalFailed, totalPassed);
            EndHtml(sb);

            FileStream f = new FileStream(htmlPath, FileMode.Create, FileAccess.Write);
            using (StreamWriter s = new StreamWriter(f))
                s.WriteLine(sb.ToString());
            if (File.Exists(htmlPath))
            {
                Console.WriteLine("Report Generated");
            }
        }
開發者ID:geeksree,項目名稱:cSharpGeeks,代碼行數:73,代碼來源:HtmlReportParser.cs

示例4: import

        private void import(string filename)
        {
            try {
                XmlDataDocument xml_doc = new XmlDataDocument ();

                xml_doc.Load (filename);

                var lessonNodes = xml_doc.SelectNodes ("//lesson");

                foreach (XmlNode ln in lessonNodes) {

                    int id = Convert.ToInt32 (getAttributeOrDefault (ln, "id", "-1"));
                    string description = getAttributeOrDefault (ln, "description", "No description set");

                    var lesson = new LessonNode (id, description);

                    var pairNodes = ln.SelectNodes ("pair");
                    foreach (XmlNode pn in pairNodes) {
                        lesson.PairStore.AddNode (new PairNode (SelectTextNode (pn, "en"), SelectTextNode (pn, "de")));
                    }

                    LessonStore.AddNode (lesson);
                }
            } catch (FileNotFoundException) {

            }
        }
開發者ID:mru00,項目名稱:vocab,代碼行數:27,代碼來源:MainWindow.cs


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