C#读取含有xmlns的XML文件
1 类似xmlns=""的文件
示例XML文件:
<?xml version="1.0" encoding="UTF-8"?>
<WebSrvMessage xmlns="http://www.lenoval.com/">
<version>1.0</version>
<DataContent>
<DateTag>2010-5-17</DateTag>
</DataContent>
</WebSrvMessage>
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
//添加命名空间,前缀可随意命名
nsmgr.AddNamespace("lvl", "http://www.lenoval.com/");
//在路径前面使用前面定义的前缀
XmlNode datatag = doc.DocumentElement.SelectSingleNode("lvl:QryDataContent/lvl:DateTag", nsmgr);
2 类似xmlns:xxxx=""的文件
如:xmlns:lenoval="http://www.lenoval.com/">
可在上面的代码中添加命名空间:
//添加命名空间,前缀可随意命名
nsmgr.AddNamespace("lenoval", "http://www.lenoval.com/");
//在路径前面使用前面定义的前缀
XmlNode datatag = doc.DocumentElement.SelectSingleNode("lenoval:QryDataContent/lenoval:DateTag", nsmgr);
相关文档:
常用的系列化定义(using System.Xml.Serialization;)
[XmlAttribute("name")] // 定义<Tag name="…"></Tag>
[XmlElement("label")] // 定义<label>…</label>
[XmlIgnoreAttrib ......
page.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="page.xsl" ?>
<list>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
& ......
下面给出了使用C# 开发的一个压缩ACCESS数据库的程序
像FolderBrowserDialog(用于浏览选择文件夹的对话框)、MessageBox(消息处理对话框)、DirectoryInfo(目录信息,可用于创建、检测是否存在等对目录的操作)、FileInfo(文件信息,可用于文件的检测、文件信息的获取、复制等操作)、DataGridView(数据表格控件,用� ......
代码如下:
DECLARE
@TempTable table(UserID int , UserName nvarchar(50));
insert into
@TempTable (UserID,UserName) values (1,'a')
insert into @TempTable
(UserID,UserName) values (2,'b')
select UserID,UserName
from @TempTable FOR XML PATH
运行这段脚本,将生成如下结果:
复制代码
......
Introduction
This article is about passing data between VB.NET/C# WinForms and JavaScript.
Before reading further, let me warn you that this article is not about ASP.NET. Concepts covered in the article are applied to Desktop applications.
Background
I was working on a project which required dat ......