<?xml version="1.0" encoding="gb2312"?>
<Images>
<Image Imgpath="aa.jpg" Data="2005年11月6日" Id="79fe5eefa857b38eadc2e86018285a9" IsPublic="1" ImgTitle="dd"><![CDATA[dfdfdfd]]></Image>
<Image Imgpath="eee3.jpg" Data="2005年11月6日" Id="278c8f3369b4c21e4cc89fc4cdd9daa" IsPublic="1" ImgTitle="aa"><![CDATA[fsafsgfsdf]]></Image>
<Images>这是我的XML文件,我想把<Image>里面的Imgpath的属性值都取出来,该项如何写呢有多个<Image>标签
<Images>
<Image Imgpath="aa.jpg" Data="2005年11月6日" Id="79fe5eefa857b38eadc2e86018285a9" IsPublic="1" ImgTitle="dd"><![CDATA[dfdfdfd]]></Image>
<Image Imgpath="eee3.jpg" Data="2005年11月6日" Id="278c8f3369b4c21e4cc89fc4cdd9daa" IsPublic="1" ImgTitle="aa"><![CDATA[fsafsgfsdf]]></Image>
<Images>这是我的XML文件,我想把<Image>里面的Imgpath的属性值都取出来,该项如何写呢有多个<Image>标签
using System.IO;
using System.Xml;public class Sample { public static void Main() { XmlDocument doc = new XmlDocument();
doc.Load("booksort.xml"); XmlNodeList nodeList;
XmlNode root = doc.DocumentElement; nodeList=root.SelectNodes("descendant::book[author/last-name='Austen']");
//Change the price on the books.
foreach (XmlNode book in nodeList)
{
book.LastChild.InnerText="15.95";
} Console.WriteLine("Display the modified XML document....");
doc.Save(Console.Out);
}
}
[Visual Basic, C#] 该示例使用文件 booksort.xml 作为输入。
<?xml version="1.0"?>
<!-- A fragment of a book store inventory database -->
<bookstore xmlns:bk="urn:samples">
<book genre="novel" publicationdate="1997" bk:ISBN="1-861001-57-8">
<title>Pride And Prejudice</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>24.95</price>
</book>
<book genre="novel" publicationdate="1992" bk:ISBN="1-861002-30-1">
<title>The Handmaid's Tale</title>
<author>
<first-name>Margaret</first-name>
<last-name>Atwood</last-name>
</author>
<price>29.95</price>
</book>
<book genre="novel" publicationdate="1991" bk:ISBN="1-861001-57-6">
<title>Emma</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>19.95</price>
</book>
<book genre="novel" publicationdate="1982" bk:ISBN="1-861001-45-3">
<title>Sense and Sensibility</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>19.95</price>
</book>
</bookstore>
1.用document文档来读取
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load();
XmlNodeList list = xmldoc.SelectNode("Image");
foreach(XmlNode node in list)
{
TextBox1.Text = node.Attributes;
}
2.用datasetDataSet ds = new DataSet();
ds.ReadXml();
TextBox1.Text = ds.Tables["Image"].Rows[0]["Imgpath"]