今天在学习XML
在看书上程序时
有这样几个东西看不懂
using MSXML2
private XMLDocument doc
doc = DOMDocument30Class()//这个是干什么的类 还是接口啊
doc.load(@"c:\books.XML")//这个路径是干什么啊 selectNodes("bookstore/book")//这句也不知道干什么的请有学过.NET的朋友解释一下这个XML的意思
在看书上程序时
有这样几个东西看不懂
using MSXML2
private XMLDocument doc
doc = DOMDocument30Class()//这个是干什么的类 还是接口啊
doc.load(@"c:\books.XML")//这个路径是干什么啊 selectNodes("bookstore/book")//这句也不知道干什么的请有学过.NET的朋友解释一下这个XML的意思
using System.Xml;XmlDocument doc = new XmlDocument(); //创建一个xmldocument对象
doc.Load(@"c:\books.xml"); //载入xml文件
selectNodes("bookstore/book");//使用xpath选择节点
然后就可以using MSXML了
这里面包含了这个东西 :DOMDocument30Class()
不知道是什么东东、
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>