易截截图软件、单文件、免安装、纯绿色、仅160KB

C#序列化xml的完整例子

C#序列化xml
关键步骤:
XmlSerializer xSerializer = new XmlSerializer(typeof(MyObj));
StringWriter sWriter = new StringWriter(CultureInfo.InvariantCulture);
XmlTextWriter xTextWriter = new XmlTextWriter(sWriter);
XmlDocument xmlDoc = new XmlDocument();
xSerializer.Serialize(xTextWriter, myObj);
xmlDoc.LoadXml(sWriter.ToString()); 
需要说明的是,如果要序列化的object所在的类里有带参数的构造函数,还必须添加一个无参数的构造函数,否则,会报object cannot be serialized because it does not have a parameterless constructor的错误。下面是一个完整的实例,仅供参考。
using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
/* The XmlRootAttribute allows you to set an alternate name
(PurchaseOrder) of the XML element, the element namespace; by
default, the XmlSerializer uses the class name. The attribute
also allows you to set the XML namespace for the element. Lastly,
the attribute sets the IsNullable property, which specifies whether
the xsi:null attribute appears if the class instance is set to
a null reference. */
[XmlRootAttribute("PurchaseOrder", Namespace="http://www.cpandl.com",
IsNullable = false)]
public class PurchaseOrder
{
public Address ShipTo;
public string OrderDate;
/* The XmlArrayAttribute changes the XML element name
from the default of "OrderedItems" to "Items". */
[XmlArrayAttribute("Items")]
public OrderedItem[] OrderedItems;
public decimal SubTotal;
public decimal ShipCost;
public decimal TotalCost;
}
public class Address
{
/* The XmlAttribute instructs the XmlSerializer to serialize the Name
field as an XML attribute instead of an XML element (the default
behavior). */
[XmlAttribute]
public string Name;
public string Line1;
/* Setting the IsNull


相关文档:

asp /asp.net c#链接Orcale 数据库的方案

1,在web服务器上安装Oracle数据库客户端,这是连接Oracle数据库的基础(但,不一定是必须的)。
2,在客户端的Net Manager 中进行配置服务的名称,配置如图(这一点非常的重要以后的链接全都在这个服务名称的基础上进行的)
3,ASP链接服务的链接字符串和方法如下:
<%
connstr= "Provider=MSDAORA.1;Password=***; ......

XMLNameSpace XML命名空间

XML 命名空间提供了一种避免元素命名冲突的方法。
命名空间属性一般放置在元素的开始标记处,其使用语法如下所示:
xmlns:namespace-prefix="namespace",
例如:xmlns:f="http://www.w3schools.com/furniture"
W3C 命名规范声明命名空间本身就是一个统一资源标示符,Uniform Resource Identifier (URI)。
asp.net读取X ......

使用JAVA和C#开发Ribbon界面

Ribbon 原来出现在 Microsoft Office 2007 的 Word、Excel 和 Powerpoint 組件中,后来也被运用到 Windows 7 的一些附加组件等其它软件中,如画图和写字板。它是一个收藏了命令按钮和图标的面板。它把命令组织成一组"标签",每一组包含了相关的命令。每一个应用程序都有一个不同的标签组,展示了程序所提供 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号