U Have Website We have Cash
If you have website put our banner on it, make money for each visitor
dollarsincome.com

想想

女人一定要有勇气,无论是对爱情也好,对生活也好。如果什么事总是畏首畏尾,那么人生就白白流过了.

导航

在xml搜索节点(两种方法)

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();//建立文档对象
            try
            {
                doc.Load("../../myOrder.xml");
                //在xmlDocument对象中搜索元素
                Console.WriteLine("");
                XmlNodeList myNodeList = doc.GetElementsByTagName("品名");
                for (int i = 0; i < myNodeList;i++ )
                {
                    Console.WriteLine(myNodeList[i].Name+":"+myNodeList[i].InnerText);
                }
                //在xmlElement对象中搜索元素
                Console.WriteLine("在xmlElement对象中搜索元素");
                XmlElement myElement = doc.DocumentElement;
                myElement = (XmlElement)myElement.LastChild;
                myNodeList = myElement.GetElementsByTagName("品名");
                for (int i = 0; i < myNodeList; i++)
                {
                    Console.WriteLine(myNodeList[i].Name + ":" + myNodeList[i].InnerText);

                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();//辅助代码,用于保留控制台窗口
        }
    }
}

posted on 2006-09-16 22:18  想想  阅读(2858)  评论(2编辑  收藏  举报