C#中用XmlDocument对象获取XML文件中的节点值
xml文件:
<?xml version="1.0" encoding="utf-8" ?>
<bookstore>
<book>
<title lang="eng">Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title lang="eng">Learning XML</title>
<price>39.98</price>
</book>
<bookstore>
<title lang="eng">Learning C#</title>
<price>55.23</price>
</bookstore>
<item name="1">第一个item</item>
<item name="2">
<item name="1">这个结点(1)</item>
<item name="2">这个结点(2)</item>
<book>
<title lang="cn">Learning C</title>
<price>60.95</price>
</book>
</item>
</bookstore>
XmlDocument xdoc = new XmlDocument();
xdoc.Load(Server.MapPath("books.xml"));
XmlNodeList xnl = xdoc.SelectNodes("/bookstore/book");
string nodeTempStr = "";
foreach (XmlNode node in xnl)
{
nodeTempStr = node.InnerText;
node
相关文档:
以前在博客上发过,经人提醒DataSet已自带读写XML的功能,于是便删了,
不过在实践中感觉封装一层后,使用起来还是蛮方便的。故再次重发。
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;
using System.Xml;
namespace XmlDesign
{
class XmlDatasetC ......
///通过传入的特定XML字符串,通过 ReadXml函数读取到DataSet中。
protected static DataSet GetDataSetByXml(string xmlData)
{
try
{
&nbs ......
VC++中操作XML(MFC、SDK)
2009年01月07日 星期三 22:33
XML在Win32程序方面应该没有在Web方面应用得多,很多
Win32程序也只是用XML来存存配置信息而已,而且没有足够
的好处的话还不如用 ini。VC++里操作XML有两个库可以用:
MSXML和XmlLite。MSXML又细分了两种接口:DOM和SAX2。XP没自带有 XmlLite,只自带有2.x、3 ......
<?xml version="1.0" encoding="gb2312" ?>
<?xml-stylesheet type="tet/css" href="mystyle.css" ?>
<%@ page errorPage="error.jap" %>
<%@ page contentType="text/xml" %>
<realmarid>
皇马花名册
<athlete>
<name>齐达内</name>
<country> ......
一、建立网页
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<script language="javascript" type="text/javascript">
<!-- 提供给C#程序调用的方法 -->
function messageBox(message)
{
alert(message);
}
</script>
</head>
& ......