易截截图软件、单文件、免安装、纯绿色、仅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


相关文档:

从xml读取游戏配置信息或保存

 /*
* 主要作用;
* 从xml读取游戏配置信息或保存
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Reflection;
namespace Game
{
class Config
{
Ke ......

C#处理oracle lob的例子

  protected void BindData1()
    {
        OracleConnection orcn = new OracleConnection("User ID=wesoftwcp; Password=wesoft; Data Source=oradb");
        orcn.Open();
      &nb ......

图像保存到XML文件和从XML中取出图像显示

一、保存到XML文件
//得到用户要上传的文件名
string strFilePathName = loFile.PostedFile.FileName;
string strFileName = Path.GetFileName(strFilePathName);
int FileLength = loFile.PostedFile.ContentLength;
if(FileLength<=0)
return; ......

超级大笨狼中国象棋(js+xml)

<html xmlns:v="urn:schemas-microsoft-com:vml">
<head>
 <STYLE>
  v\:* { Behavior: url(#default#VML) }
  body {
   background-color:DarkGoldenrod;
   margin-left: 10px;
 &nbs ......

FLASH+XML不显示中文或无法显示中文的解决方法

常常在网上看到一些很的FLASH效果可是下下来后才发现中文不支持或都中文无法显示的问题,所以在网上找了很多资料终于找到了一个简单的方法来解决这个问题,在这里与大家分享一下。
点南嵌入按钮,按下ctrl选中大写,小写,数字,标点符号,中文(全部)后,确定!!
 这样就OK了。 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号