xml的序列化和反序列化
XML序列化与反序列化 整理文档
XML序列化与反序列化
// OBJECT -> XML
public static void SaveXml(string filePath, object obj) { SaveXml(filePath, obj, obj.GetType()); }
public static void SaveXml(string filePath, object obj, System.Type type)
{
using (System.IO.StreamWriter writer = new System.IO.StreamWriter(filePath))
{
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(type);
xs.Serialize(writer, obj);
writer.Close();
}
}
// XML -> OBJECT
public static object LoadXml(string filePath, System.Type type)
{
if (!System.IO.File.Exists(filePath))
return null;
using (System.IO.StreamReader reader = new System.IO.StreamReader(filePath))
{
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(type);
object obj = xs.Deserialize(reader);
reader.Close();
return obj;
}
}
相关的常用Attribute(命名空间System.Xml.Serialization )
[XmlRootAttribute("PurchaseOrder", Namespace=
相关文档:
declare @x xml
set @x='
<ROOT>
<SM>
<SMID>88</SMID>
<SMCD>A5</SMCD>
<SMNM>刘洋</SMNM>
<NDS>
<ND>
<SF>3</SF>
<NDID>88</NDID>
<NDCD>A5< ......
方法一 :使用XML控件
<% @ Page Language="C#"%>
<html>
<body>
<h3><font face="Verdana">读取XML方法一</font></h3>
<from runat=server>
<asp:Xml id="xml1" DocumentSource="grade.xml" runat="server" />
</from>
</body>
</ ......
//******************** 头文件 Markup.h *******************
// Markup.h: interface for the CMarkup class.
//
// Markup Release 11.2
// Copyright (C) 2009 First Objective Software, Inc. All rights reserved
// Go to www.firstobject.com for the latest CMarkup and EDOM documentation
// ......