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();//辅助代码,用于保留控制台窗口
        }
    }
}

相关文章:

  • 2021-10-22
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2021-09-28
  • 2022-12-23
  • 2021-06-22
  • 2021-07-17
猜你喜欢
  • 2022-12-23
  • 2021-11-21
  • 2021-08-10
  • 2022-12-23
  • 2021-04-29
  • 2021-06-20
  • 2021-07-21
相关资源
相似解决方案