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


C# XmlDataDocument.GetElementsByTagName方法代碼示例

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


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

示例1: getWeatherData

        public IDictionary<String, String> getWeatherData(String lat, String lon)
        {
            XmlDataDocument doc = new XmlDataDocument();
            IDictionary<String, String> data = new Dictionary<String, String>();
            String url ="http://api.openweathermap.org/data/2.5/forecast/daily?lat=" + lat + "&lon=" + lon + "&cnt=5&mode=xml";
            doc.Load(url);

            XmlNodeList locationList = doc.GetElementsByTagName("location");
            XmlNodeList foreCastList = doc.GetElementsByTagName("time");

            data["City"] = locationList[0].SelectSingleNode("name").InnerText;
            data["Country"] = locationList[0].SelectSingleNode("country").InnerText;

            String temperature,wind,clouds;

            for (int i = 0; i < 5; i++)
            {
                temperature = "Temperature : Morn = " + foreCastList[i].SelectSingleNode("temperature").Attributes["morn"].Value +
                            ",Evening = " + foreCastList[i].SelectSingleNode("temperature").Attributes["eve"].Value + ",Night = " + foreCastList[i].SelectSingleNode("temperature").Attributes["night"].Value;
                wind = "Wind : " + foreCastList[i].SelectSingleNode("windSpeed").Attributes["name"].Value;
                clouds = "Clouds : " + foreCastList[i].SelectSingleNode("clouds").Attributes["value"].Value;

                data[foreCastList[i].Attributes["day"].Value] = temperature + " | " + wind + " | " + clouds;
            }
            return data;
        }
開發者ID:sravyaguturu,項目名稱:c-WebServices,代碼行數:26,代碼來源:Weather.svc.cs

示例2: getLatLong

        public IDictionary<String, String> getLatLong(String zipCode)
        {
            XmlDataDocument doc = new XmlDataDocument();
            List<String> data = new List<String>();
            String url = "http://maps.googleapis.com/maps/api/geocode/xml?address=" + zipCode;
            doc.Load(url);

            XmlNodeList status = doc.GetElementsByTagName("status");
            String res_status = status[0].InnerText;
            if (!res_status.Equals("OK"))
            {
                data.Add("No Result");
            }

            XmlNodeList result = doc.GetElementsByTagName("result");
            XmlNodeList list = null,location = null;

            String latitude = null, longitude = null;

            for (int i = 0; i < result.Count; i++)
            {
                list = doc.GetElementsByTagName("geometry");
            }
            for (int i = 0; i < list.Count; i++)
            {
                location = doc.GetElementsByTagName("location");
            }

            latitude = location[0].SelectSingleNode("lat").InnerText;
            longitude = location[0].SelectSingleNode("lng").InnerText;
            return  getWeatherData(latitude,longitude);
        }
開發者ID:sravyaguturu,項目名稱:c-WebServices,代碼行數:32,代碼來源:Weather.svc.cs

示例3: button1_Click

        private void button1_Click(object sender, System.EventArgs e)
        {
            XmlDataDocument doc = new XmlDataDocument ();
            doc.Load ( "locdata.xml" );
            XmlNodeList nodes = doc.GetElementsByTagName("city");
            foreach ( XmlNode n in nodes )
            {
                listBox1.Items.Add ( n.InnerText );

            }
            label1.Text = string.Format("Total {0} Item(s).", listBox1.Items.Count);

            //			StreamReader reader = new StreamReader ( "loctest2.csv" );
            //			string contents = reader.ReadToEnd ();
            //			reader.Close ();
            //			foreach ( string s in contents.Split ( "\n\r".ToCharArray() ) )
            //			{
            //				if ( s.Trim() == string.Empty ) continue;
            //				foreach ( string p in s.Split ( ",".ToCharArray() ) )
            //				{
            //					string temp = p.Replace ( "\"", "" );
            //					listBox1.Items.Add ( temp.Trim() );
            //				}
            //
            //
            //			}
        }
開發者ID:usmanghani,項目名稱:Misc,代碼行數:27,代碼來源:Form1.cs

示例4: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            //try
            //{
                if (this.RssUrl.Length == 0)
                    throw new ApplicationException("Не указана ссылка на RSS-ленту.");

                XmlDataDocument feed = new XmlDataDocument();
                feed.Load(GetFullUrl(this.RssUrl));
                XmlNodeList posts = feed.GetElementsByTagName("item");

                DataTable table = new DataTable("Feed");
                table.Columns.Add("Title", typeof(string));
                table.Columns.Add("Description", typeof(string));
                table.Columns.Add("Link", typeof(string));
                table.Columns.Add("PubDate", typeof(DateTime));

                foreach (XmlNode post in posts)
                {
                    DataRow row = table.NewRow();
                    row["Title"] = post["title"].InnerText;
                    row["Description"] = post["description"].InnerText.Trim();
                    row["Link"] = post["link"].InnerText;
                    row["PubDate"] = DateTime.Parse(post["pubDate"].InnerText);
                    table.Rows.Add(row);
                }

                dlArticles.DataSource = table;
                dlArticles.DataBind();
            //}
            /*catch (Exception)
            {
                this.Visible = false;
            }*/
        }
開發者ID:Nevs12,項目名稱:LiveandevSite,代碼行數:35,代碼來源:RssReader.ascx.cs

示例5: createCsvFile

        private void createCsvFile()
        {
            XmlDataDocument xmldoc = new XmlDataDocument();
            string name = null;
            string year = null;
            string corp = null;
            string line = null;
            string code = null;
            XmlNodeList childs = null;
            StreamWriter file = new StreamWriter(mamePath + "roms.csv", false);
            FileStream fs = new FileStream(mamePath + "mame.xml", FileMode.Open, FileAccess.Read);
            xmldoc.Load(fs);
            XmlNodeList machineNodes = xmldoc.GetElementsByTagName("machine");

            for (int i = 0; i < machineNodes.Count; i++)
            {
                code = machineNodes[i].Attributes.GetNamedItem("name").InnerText.Trim();
                childs = machineNodes[i].ChildNodes;
                name = childs.Count > 0 ?  childs.Item(0).InnerText.Trim() : "";
                year = childs.Count > 1 ? childs.Item(1).InnerText.Trim() : "";
                corp = childs.Count > 2 ? childs.Item(2).InnerText.Trim() : "";
                line = segment(code) + ", " + segment(name)  + ", " + segment(year) + ", " + segment(corp);
                file.WriteLine(line);
                //if (i > 10) {
                //    break;
                //}
            }
            file.Close();
            fs.Close();
        }
開發者ID:MyroStadler,項目名稱:MAME-Tool,代碼行數:30,代碼來源:MainWindow.xaml.cs

示例6: readChannelFeed

    public void readChannelFeed()
    {
        XmlDataDocument xmldoc = new XmlDataDocument();
        XmlNodeList xmlnode;
        int i = 0;
        //string str = null;
        xmldoc.Load(formHTTPrequest());
        xmlnode = xmldoc.GetElementsByTagName("feed");
        feedCount = xmlnode.Count;

        dates = new string[xmlnode.Count];
        ids = new string[xmlnode.Count];
        temp = new string[xmlnode.Count];
        air = new string[xmlnode.Count];
        soil = new string[xmlnode.Count];
        light = new string[xmlnode.Count];
        co2_1 = new string[xmlnode.Count];
        co2_2 = new string[xmlnode.Count];
        out_temp = new string[xmlnode.Count];

        for (i = 0; i <= xmlnode.Count - 1; i++)
        {
            dates[i] = xmlnode[i].ChildNodes.Item(0).InnerText.Trim();
            ids[i] = xmlnode[i].ChildNodes.Item(1).InnerText.Trim();
            temp[i] = xmlnode[i].ChildNodes.Item(2).InnerText.Trim();
            air[i] = xmlnode[i].ChildNodes.Item(3).InnerText.Trim();
            soil[i] = xmlnode[i].ChildNodes.Item(4).InnerText.Trim();
            light[i] = xmlnode[i].ChildNodes.Item(5).InnerText.Trim();
            co2_1[i] = xmlnode[i].ChildNodes.Item(6).InnerText.Trim();
            co2_2[i] = xmlnode[i].ChildNodes.Item(7).InnerText.Trim();
            out_temp[i] = xmlnode[i].ChildNodes.Item(8).InnerText.Trim();

        }
    }
開發者ID:kristijonaslucenko,項目名稱:Smart_Plant,代碼行數:34,代碼來源:ThingsSpeakFeedReader.cs

示例7: FindDiscount

 /// <summary>
 /// Find the discount percentage applicable to the user
 /// </summary>
 /// <returns>Discount percentage</returns>
 public int FindDiscount()
 {
     int discountPercentage = 0;
     try
     {
         XmlDataDocument xmldoc = new XmlDataDocument();
         XmlNodeList xmlnode;
         if (user is Employee)
         {
             FileStream fs = new FileStream(Directory.GetCurrentDirectory() + "\\ApplicableDiscounts\\EmployeeDiscount.xml", FileMode.Open, FileAccess.Read);
             xmldoc.Load(fs);
             xmlnode = xmldoc.GetElementsByTagName("Discount");
             String discount = xmlnode[0].FirstChild.Value;
             discountPercentage = Int32.Parse(discount);
         }
         if (user is Affiliate)
         {
             FileStream fs = new FileStream(Directory.GetCurrentDirectory() + "\\ApplicableDiscounts\\AffiliateDiscount.xml", FileMode.Open, FileAccess.Read);
             xmldoc.Load(fs);
             xmlnode = xmldoc.GetElementsByTagName("Discount");
             String discount = xmlnode[0].FirstChild.Value;
             discountPercentage = Int32.Parse(discount);
         }
         if (user is Customer && (user as Customer).AssociatedSinceYears >= 2)
         {
             FileStream fs = new FileStream(Directory.GetCurrentDirectory() + "\\ApplicableDiscounts\\CustomerDiscount.xml", FileMode.Open, FileAccess.Read);
             xmldoc.Load(fs);
             xmlnode = xmldoc.GetElementsByTagName("Discount");
             String discount = xmlnode[0].FirstChild.Value;
             discountPercentage = Int32.Parse(discount);
         }
     }
     catch(Exception ex)
     {
         Console.WriteLine("Exception while loading xml data for discount specific to to the type of user");
     }
     return discountPercentage;
 }
開發者ID:vinayv1234,項目名稱:Discount,代碼行數:42,代碼來源:DiscountReader.cs

示例8: GetTransferEntry

        protected override BankTransfer GetTransferEntry(string entry)
        {
            SieradzBankTransfer mBankTransfer = new SieradzBankTransfer();
            #pragma warning disable 618
            XmlDocument xmlNode = new XmlDataDocument();
            #pragma warning restore 618
            string datePattern = "d.m.yyyy";
            DateTime currentDate = DateTime.Now;
            var bankDictionary = SieradzBankTransfersUtils.Instance;

            xmlNode.LoadXml(entry);
            //TODO it's possible to reduce that sphagetti?
            // IT FCKIN IS!         @UCTT
            mBankTransfer.TransferInfo.Amount = xmlNode.GetElementsByTagName("Amount").Item(0).InnerText;
            mBankTransfer.TransferInfo.DestinationAccountNumber = xmlNode.GetElementsByTagName("DestinationAccountNumber").Item(0).InnerText;
            mBankTransfer.TransferInfo.DestinationPersonName = xmlNode.GetElementsByTagName("DestinationPersonName").Item(0).InnerText;
            mBankTransfer.TransferInfo.SourceAccountNumber = xmlNode.GetElementsByTagName("SourceAccountNumber").Item(0).InnerText;
            mBankTransfer.TransferInfo.TransferDate = currentDate.ToString(datePattern);
            mBankTransfer.TransferInfo.TransferTitle = xmlNode.GetElementsByTagName("TransferTitle").Item(0).InnerText;
            mBankTransfer.SourceBank = bankDictionary.GetBankName(mBankTransfer.TransferInfo.SourceAccountNumber.Substring(2, 4));
            mBankTransfer.DestinationBank = bankDictionary.GetBankName(mBankTransfer.TransferInfo.DestinationAccountNumber.Substring(2, 4));
            return mBankTransfer;
        }
開發者ID:sparrow41,項目名稱:training,代碼行數:23,代碼來源:TypowyAdamBankTransfersParser.cs

示例9: GetBankTransfers

        public override List<BankTransfer> GetBankTransfers()
        {
            BankFileOperation = new SieradzFileOperation();
            #pragma warning disable 618
            XmlDocument xmlFile= new XmlDataDocument();
            #pragma warning restore 618
            List<BankTransfer> mBankTransferList = new List<BankTransfer>();
            xmlFile.LoadXml(BankFileOperation.GetFileContent(SieradzBankFilesPathHolder.TransferFilesPath + @"mBankTransfers.xml"));
            foreach (var childNode in xmlFile.DocumentElement.ChildNodes)
            {
                mBankTransferList.Add(GetTransferEntry(xmlFile.GetElementsByTagName((string) childNode.GetType().GetProperty("Name").GetValue(childNode)).Item(0).OuterXml));
            }

            return mBankTransferList;
        }
開發者ID:sparrow41,項目名稱:training,代碼行數:15,代碼來源:TypowyAdamBankTransfersParser.cs

示例10: button2_Click

 /// <summary>
 /// How to open and read an XML file in C#
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button2_Click(object sender, EventArgs e)
 {
     XmlDataDocument xmldoc = new XmlDataDocument();
     XmlNodeList xmlnode;
     int i = 0;
     string str = null;
     FileStream fs = new FileStream("product.xml", FileMode.Open, FileAccess.Read);
     xmldoc.Load(fs);
     xmlnode = xmldoc.GetElementsByTagName("Product");
     for (i = 0; i <= xmlnode.Count - 1; i++)
     {
         //xmlnode[i].ChildNodes.Item(0).InnerText.Trim();
         str = xmlnode[i].ChildNodes.Item(0).InnerText.Trim() + " | " + xmlnode[i].ChildNodes.Item(1).InnerText.Trim() + " | " + xmlnode[i].ChildNodes.Item(2).InnerText.Trim();
         MessageBox.Show(str);
     }
 }
開發者ID:icegithub,項目名稱:csharp-exercise,代碼行數:21,代碼來源:HowtocreateanXMLfileinCSharp.cs

示例11: rainfallImportXML

        public rainfallImportXML(String StationsFile, String ReadingsFile, ref Dictionary<string, List<StationReading>> precip)
        {
            Stations = new XmlDataDocument();
            Readings = new XmlDataDocument();
            dStations = new Dictionary<string, Station>();
            dReadings = new List<Reading>();
            dStationReadings = new Dictionary<string, StationReading>();

            StreamReader sr = new StreamReader(StationsFile);
            String xmlStr = sr.ReadToEnd();

            Stations.LoadXml(xmlStr);
            sr = new StreamReader(ReadingsFile);
            xmlStr = sr.ReadToEnd();

            Readings.LoadXml(xmlStr);

            XmlNodeList root = Stations.GetElementsByTagName("site");
            foreach (XmlNode n in root)
            {
                dStations.Add(n.ChildNodes[1].InnerXml, new Station(n.ChildNodes[1].InnerXml, Double.Parse(n.ChildNodes[3].InnerXml), Double.Parse(n.ChildNodes[4].InnerXml), n.ChildNodes[2].InnerXml));
            }
            root = Readings.GetElementsByTagName("element");
            foreach (XmlNode n in root)
            {
                dReadings.Add(new Reading(n.Attributes.GetNamedItem("station_id").Value, n.Attributes.GetNamedItem("date").Value, n.Attributes.GetNamedItem("precip_interval").Value, Double.Parse(n.Attributes.GetNamedItem("value").Value)));
            }
            Station curStation;
            foreach (Reading r in dReadings)
            {
                if (precip.ContainsKey(r.DataTime))
                {
                    curStation = dStations[r.StationID];
                    precip[r.DataTime].Add(new StationReading(curStation.Lat, curStation.Lon, r.Date, r.DataTime, r.Value));
                }
                else
                {
                    List<StationReading> lsr = new List<StationReading>();
                    curStation = dStations[r.StationID];
                    lsr.Add(new StationReading(curStation.Lat, curStation.Lon, r.Date, r.DataTime, r.Value));
                    precip.Add(r.DataTime, lsr);
                }
            }
        }
開發者ID:skarlath,項目名稱:spaceapps_MIAMI,代碼行數:44,代碼來源:rainfallImportXML.cs

示例12: GetDataUsingDataContract

        /*  public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }*/
        public IDictionary<string, string> getCrimeData(String zipCode)
        {
            XmlDataDocument doc = new XmlDataDocument();
            IDictionary<String, String> data = new Dictionary<String, String>();
            String url = "https://azure.geodataservice.net/GeoDataService.svc/GetUSDemographics?includecrimedata=true&zipcode=" + zipCode ;
            doc.Load(url);

            XmlNodeList elementList = doc.GetElementsByTagName("element");
            XmlNode root = elementList[0];
            //Display the contents of the child nodes.
            if (root.HasChildNodes)
            {
                for (int i = 0; i < root.ChildNodes.Count; i++)
                {
                    data.Add(root.ChildNodes[i].Name,root.ChildNodes[i].InnerText);
                }
            }

            return data;
        }
開發者ID:sravyaguturu,項目名稱:c-WebServices,代碼行數:37,代碼來源:Crime.svc.cs

示例13: btnChoose_Click

        private void btnChoose_Click(object sender, RoutedEventArgs e)
        {
            flyPackages.IsOpen = true;

            lstPackages.Items.Clear();
            WebResponse response = WebRequest.Create(@"https://realmofthemadgod.appspot.com/package/getPackages").GetResponse();

            XmlDataDocument xmlDataDocument = new XmlDataDocument();
            xmlDataDocument.Load(response.GetResponseStream());
            XmlNodeList elementsByTagName = xmlDataDocument.GetElementsByTagName("Package");
            for (int index = 0; index < elementsByTagName.Count; ++index)
            {
                string _name = elementsByTagName[index].ChildNodes.Item(0).InnerText.Trim();
                string _id = elementsByTagName[index].Attributes["id"].Value;
                string _price = elementsByTagName[index].ChildNodes.Item(1).InnerText.Trim();
                string _url = elementsByTagName[index].ChildNodes.Item(5).InnerText.Trim();
                string _end = elementsByTagName[index].ChildNodes.Item(6).InnerText.Trim();

                lstPackages.Items.Add("[" + _id + "] " + _name + " - " + _price + "gold");
            }
        }
開發者ID:nzambii,項目名稱:MassPackageBuyer,代碼行數:21,代碼來源:MainWindow.xaml.cs

示例14: ReadingXml

        public List<ProcessMonitor> ReadingXml()
        {
            XmlDataDocument xmldoc = new XmlDataDocument();
            XmlNodeList xmlnode;
            int i = 0;
            List<ProcessMonitor> processes = new List<ProcessMonitor>();
            string path = Path.GetDirectoryName(Application.ExecutablePath)+"\\Process.xml";

            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
            xmldoc.Load(fs);
            xmlnode = xmldoc.GetElementsByTagName("ProcessMonitor");
            for (i = 0; i <= xmlnode.Count - 1; i++)
            {
                ProcessMonitor process = new ProcessMonitor();
                process.ProcessName = xmlnode[i].ChildNodes.Item(0).InnerText.Trim();
                process.NotificationList = xmlnode[i].ChildNodes.Item(1).InnerText.Trim();
                process.TimeInterval = xmlnode[i].ChildNodes.Item(2).InnerText.Trim();
                process.NotificationSubject = xmlnode[i].ChildNodes.Item(3).InnerText.Trim();
                process.NotificationMail = xmlnode[i].ChildNodes.Item(4).InnerText.Trim();

                processes.Add(process);
            }
            return processes;
        }
開發者ID:KaushikSakala,項目名稱:ProcessMonitoring,代碼行數:24,代碼來源:ServiceMonitor.cs

示例15: button3_Click

		private void button3_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
			SqlConnection conn = new SqlConnection(_connectString);
            SqlDataAdapter da = new SqlDataAdapter("SELECT Title,userid,content FROM task", conn);
			//fill the dataset
			da.Fill(ds, "Products");
			ds.WriteXml("sample.xml", XmlWriteMode.WriteSchema);
			//load data into grid
			dataGridView1.DataSource = ds.Tables[0];
            //XmlDataDocument專門為DataSet而設計
			doc = new XmlDataDocument(ds);
			//get all of the products elements
			XmlNodeList nodeLst = doc.GetElementsByTagName("Products");
            textBox1.Text = "";
            foreach (XmlNode node in nodeLst)
            {
                textBox1.Text += node.InnerXml + "\r\n";
            }
		}
開發者ID:ChegnduJackli,項目名稱:Projects,代碼行數:24,代碼來源:frmADOXML.cs


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