今天在学习XML
在看书上程序时
有这样几个东西看不懂
using MSXML2
private XMLDocument doc
doc = DOMDocument30Class()//这个是干什么的类 还是接口啊 
doc.load(@"c:\books.XML")//这个路径是干什么啊 selectNodes("bookstore/book")//这句也不知道干什么的请有学过.NET的朋友解释一下这个XML的意思

解决方案 »

  1.   

    不好意思,没见过这样写.LZ看的是什么xml书?让我也见识见识解释如下:VS2005:
    using System.Xml;XmlDocument doc = new XmlDocument();  //创建一个xmldocument对象
    doc.Load(@"c:\books.xml");   //载入xml文件
    selectNodes("bookstore/book");//使用xpath选择节点
      

  2.   

    哦 我忘记了说 ,在USING之前 我咋VS.2005里添加了引用 Microsoft XML3.0版本
    然后就可以using MSXML了
    这里面包含了这个东西 :DOMDocument30Class()
    不知道是什么东东、
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using MSXML2;namespace XmlTest
    {
        public partial class Form1 : Form
        {
            private DOMDocument30Class doc;         public Form1()
            {
                InitializeComponent();
            }        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
            {        }        private void button1_Click(object sender, EventArgs e)
            {
                //读取XML文档
                doc = new DOMDocument30Class();
                doc.load(@"F:\dhthx\exercise\xml\XmlTest\book.xml");
                //检索ISBN
                IXMLDOMNodeList NodeList;
                NodeList = doc.selectNodes("bookstore/book");            foreach (IXMLDOMNode node in NodeList)
                {
                    listBox1.Items.Add(node.attributes.getNamedItem("ISBN").text);
                }
            }
        }
    }运行不起来
    应该是ISBN的那个值显示在LISTBOX1控件上了
    是是显示不出來。
    ------------------------------------------------
    ================================================
    下面是BOOK.xml
    <?XML version='1.0'?>
    <!--This file represents afragment of a book store inventory database-->
    <bookstore>
    <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
    <title>The Autobiography of benjamin Franklin</title>
    <author>
    <first-name>Benjamin</first-name>
    <last-name>franklin</last-name>
    </author>
    <price>8.99</price>
    </book>

    <book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
    <title>The Confidence Man</title>
    <author>
    <first-name>Herman</first-name>
    <last-name>Melnille</last-name>
    </author>
    <price>11.99</price>
    </book> <book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
    <title>The Gorgias</title>
    <author>
    <first>Plato</first>
    </author>
    <price>9.99</price>
    </book>
    </bookstore>