问题一:关于操作XML的问题:
写一个上下班的考勤的程序,很简单的。就是每个员工来了后,输入工号和密码并点击上班按钮,这时候程序建立一个以员工工号为文件名的xml文件。然后将上班时间写入xml中,然后下班时候记录下班时间。怎么做才能在页面中,把每天的上下班时间写在一行内,比如上班时间2010-5-29 8:30 下班时间2010-5-29 18:00,XML文件不是太熟,只知道读取节点内容。
我的代码如下:
   XmlDocument xmldoc=new XmlDocument();
            xmldoc.Load("003.xml");
            if (xmldoc != null)
            {
                XmlNode dudu = xmldoc.SelectSingleNode("work");
            }
还是不太懂,应该如何把时间写入到XML文件中来,请给个例子好吗?还有又如何把数据读取出来呢?并添加到listview中,希望给点代码学习一下。问题二:在listiview中选择和textbox1.text相等值的行,并高亮出来。 和用鼠标选择整行,fullrowselect一样的效果就行
           int j = 0;
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                if (textBox1.Text == this.listView1.Items[i].SubItems[0].Text)
                {
                    j = i;
                }
            }
            this.listView1.SelectedIndices.Add(j);
            this.listView1.Items[j].Selected = true;我想把listiview控件中,第一列数值和textbox1.text相等的整行高亮出来。请假如何选择整行?

解决方案 »

  1.   

    问题一:
     XmlDocument xmldoc=new XmlDocument();
      xmldoc.Load("003.xml");
      if (xmldoc != null)
      {
      XmlNode dudu = xmldoc.SelectSingleNode("work");
       dudu.InnerText = "2009-01-02";  //赋值
       string s = dudu.InnerText;       //取值
      }
      
       //最后要保存
       xmldoc.Save...
      要是InnerText不好用,看下InnerXml属性,记不大清了
    问题二:
     int j = 0;
      for (int i = 0; i < listView1.Items.Count; i++)
      {
      if (textBox1.Text == this.listView1.Items[i].SubItems[0].Text)
      {
          this.listView1.Items[i].Selected = true;
        }
      }
      

  2.   

    这是以前在学校自己做的小例子。现在没时间帮你整合,你自己看看吧  static void Main(string[] args)
            {
                int k = 0;
                XmlDocument doc = new XmlDocument();
                doc.Load(AppDomain.CurrentDomain.BaseDirectory + "XMLFile1.xml");
                XmlNode root = doc.DocumentElement;
                for (int i = 0; i < root.ChildNodes.Count; i++)
                {
                    Console.WriteLine("书籍编号:{0} 书名:{1}  出版社:{2}", root.SelectNodes("书")[i].ChildNodes[0].InnerText, root.SelectNodes("书")[i].ChildNodes[1].InnerText, root.SelectNodes("书")[i].ChildNodes[2].InnerText);
                }
                Console.WriteLine("");
                Console.WriteLine("现进行xml的操作,请选择:1   添加     2  修改    3  删除   4  查询");
                string s = Console.ReadLine();
                char[] car=s.ToCharArray();
                int x=0;
                foreach (char c in car)
                {
                    if (char.IsNumber(c) == false)
                    {
                        break;
                    }
                    else
                    { 
                        x =Convert.ToInt32(s);
                    }
                }
                switch (x)
                { 
                    case 1:
                        XmlNode book = doc.CreateElement("书");
                        XmlNode bookid = doc.CreateElement("编号");
                        XmlNode bookbt = doc.CreateElement("标题");
                        XmlNode bookcbs = doc.CreateElement("出版社");
                        Console.Write("书籍编号:");
                        bookid.InnerText = Console.ReadLine();
                        for (int i = 0; i < root.ChildNodes.Count; i++)
                        {                        if (root.SelectNodes("书")[i].ChildNodes[0].InnerText == bookid.InnerText)
                            {                            Console.WriteLine("对不起!已经有此编号的书!");
                                k++;
                            }
                            else
                            {
                                if (i == root.ChildNodes.Count - 1 && k == 0)
                                {
                                    Console.Write("书名:");
                                    bookbt.InnerText = Console.ReadLine();
                                    Console.Write("出版社:");
                                    bookcbs.InnerText = Console.ReadLine();
                                    book.AppendChild(bookid);
                                    book.AppendChild(bookbt);
                                    book.AppendChild(bookcbs);
                                    root.AppendChild(book);
                                    doc.Save(AppDomain.CurrentDomain.BaseDirectory + "XMLFile1.xml");
                                }                        }
                        }
                        
                        break;
                    case 2:
                        Console.WriteLine("请输入修改的书籍编号:");
                        string str = Console.ReadLine();
                        XmlNode selectbook1 = root.SelectSingleNode("书[编号="+str+"]");
                        for (int i = 0; i < root.ChildNodes.Count; i++)
                        {
                            
                            if (root.SelectNodes("书")[i].ChildNodes[0].InnerText == str)
                            {
                                Console.Write("书名:");
                                selectbook1.ChildNodes[1].InnerText = Console.ReadLine();
                                Console.Write("出版社:");
                                selectbook1.ChildNodes[2].InnerText = Console.ReadLine();
                                doc.Save(AppDomain.CurrentDomain.BaseDirectory + "XMLFile1.xml");
                                k++;
                            }
                            else
                            {
                                if (i == root.ChildNodes.Count - 1 && k==0)
                                { 
                                    Console.WriteLine("对不起没有此编号的书!");
                                }
                                
                            }
                        }
                        break;
                    case 3:
                        Console.WriteLine("请输入要删除书的书籍编号:");
                        string str1 = Console.ReadLine();
                        for (int i = 0; i < root.ChildNodes.Count; i++)
                        {                        if (root.SelectNodes("书")[i].ChildNodes[0].InnerText == str1)
                            {
                                root.RemoveChild(root.SelectSingleNode("书[编号=" + str1 + "]"));
                                doc.Save(AppDomain.CurrentDomain.BaseDirectory + "XMLFile1.xml");
                                k++;
                            }
                            else
                            {
                                if (i == root.ChildNodes.Count - 1 && k == 0)
                                {
                                    Console.WriteLine("对不起没有此编号的书!");
                                }                        }
                        }
                        
                        break;
                    case 4:
                        Console.WriteLine("请输入查询的书籍编号:");
                        string str2 = Console.ReadLine();                    XmlNode selectbook3 = root.SelectSingleNode("书[编号=" + str2 + "]");
                        for (int i = 0; i < root.ChildNodes.Count; i++)
                        {                        if (root.SelectNodes("书")[i].ChildNodes[0].InnerText == str2)
                            {
                                Console.WriteLine("书籍编号:{0} 书名:{1}  出版社:{2}", selectbook3.ChildNodes[0].InnerText, selectbook3.ChildNodes[1].InnerText, selectbook3.ChildNodes[2].InnerText);
                        
                                k++;
                            }
                            else
                            {
                                if (i == root.ChildNodes.Count - 1 && k == 0)
                                {
                                    Console.WriteLine("对不起没有此编号的书!");
                                }                        }
                        }
                        //XmlNode selectbook = root.SelectSingleNode("书[编号='001']");
                        //Console.WriteLine(selectbook.ChildNodes[1].InnerText);                    //XmlNodeList selbook = root.SelectNodes("书");
                        //Console.WriteLine(selbook[0].ChildNodes[1].InnerText);
                        break;
                    default:
                        Console.WriteLine("请按要求操作!谢谢!");
                        break;
                }
                
            }
      

  3.   

    XML 你可以把所有的员工信息都放在一个XML文件里面啊,那样又不麻烦