C#小Tip:Xml操作简明手册 1
1)Xml文档示例(xmlsample.xml):
Code
<?xml version="1.0" encoding="iso-8859-1" ?>
<music>
<song title="Oh,girl">
<artist>The Chi-lites</artist>
<genre>Soul</genre>
<album>A lonely man</album>
<year>1972</year>
</song>
<song title="What if">
<artist>Babyface</artist>
<genre>R&B</genre>
<album>unknown</album>
<year></year>
</song>
<song title="How come,how long">
<artist>Babyface</artist>
<genre>R&B</genre>
<album>The essential babyface</album>
<year>2001</year>
</song>
<song title="Drama,love &'lationship">
<artist>Babyface</artist>
<genre>R&B</genre>
<album>Grown and sexy</album>
<year>2005</year>
</song>
<song title="Burning">
<artist>Maria Arredondo</artist>
<genre>Pop</genre>
<album>Not going under</album>
<year>2004</year>
</song>
<song title="Run">
<artist>Leona Lewis</artist>
<genre>Pop</genre>
<album>Unknown</album>
<year>2008</
相关文档:
<Language from="SQL" To="C#">
<Type from="bigint" To="long" />
<Type from="binary" To="object" />
<Type from="bit" To="bool" />
<Type from="char" To="string" />
<Type from="datetime" To="DateTime" ......
C#
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("~/Config/User_yhlx_Jb.xml"));
DataView dv = ds.Tables[0].DefaultView;
//dv.RowFilter = "State=0";
this.DropDownList1.DataSource = dv;
this.DropDownList1.DataTextField = "text";
this ......
XML Schema annotation 元素
定义和用法
annotation 元素是一个顶层元素,规定 schema 的注释。
注释:可以包含 appinfo 元素(由应用程序使用的信息)和 documentation 元素(由用户读取或使用的注释或文本)。
元素信息
项目
说明
出现次数
在父元素中一次。
......
XML Schema attributeGroup 元素
定义和用法
attributeGroup 元素用于对属性声明进行组合,这样这些声明就能够以组合的形式合并到复杂类型中。
元素信息
出现次数
无限制
父元素
attributeGroup、complexType、schema、restriction (simpleContent)、extension (simpleContent)、rest ......
原先一直用BinaryFormatter来序列化挺好,可是最近发现在WinCE下是没有办法进行BinaryFormatter操作,很不爽,只能改成了BinaryWriter和BinaryReader来读写,突然想到能不能用XML来序列化?于是在网上查了些资料便写了些实践性代码,做些记录,避免以后忘记。
序列化对象
public class People
......