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

一个C# xml 序列化错误

一个C# xml 序列化错误
 
事发现场:
xml序列化的数据中存储的节点数据是
   <Module>536870912</Module>  (xml文件中)
对应的类属性是
    public short Module { get; set; }  (C#类中)
 
序列化的代码:
public static FMDSTimeSeriesDefinitionList Deserialize(string xml)
{
XmlSerializer serializer = new XmlSerializer(typeof(FMDSTimeSeriesDefinitionList));
/* If the XML document has been altered with unknown
nodes or attributes, handle them with the
UnknownNode and UnknownAttribute events.*/
serializer.UnknownNode += new
XmlNodeEventHandler(serializer_UnknownNode);
serializer.UnknownAttribute += new
XmlAttributeEventHandler(serializer_UnknownAttribute);
FMDSTimeSeriesDefinitionList tsList = null;
using (StringReader sr = new StringReader(xml))
{
try
{
tsList = (FMDSTimeSeriesDefinitionList)serializer.Deserialize(sr);
}
catch (Exception ex)
{
throw ex;
}
}
return tsList;
}
 
 
调试时会弹出异常信息:
An unhandled exception of type 'System.InvalidOperationException' occurred in FMTimeSeriesDefinition.exe
Additional information: There is an error in XML document (293, 8).
找到xml文件的293行第8列:
292:      <Module>536870912</Module>
293:      <DurationPeriodsFlag>1</DurationPeriodsFlag>
294:      <DecimalFlag>0</DecimalFlag>
 
是一个"<"标记符,看不出问题,再看前一个节点,突然发现536870912 存入short中,数据溢出。
将short改为int,问题解决。


相关文档:

如何在 XML 文件中取得指定属性的相关值?

两种方法:
其一,使用 SelectNodes 的方法;以下例子为使用此方法的处理。
其二,使用 XQuery 的方法。
    ''' <summary>
    ''' 从 XML 文件中取得对应ID 的语言值
    ''' </summary>
    ''' <param name="textID">输入的ID< ......

[转]使用ASP调用C#写的COM组件

转自: http://www.cnblogs.com/rentj1/archive/2009/02/23/1396187.html
1 新建类库MyTestDLL
2 右击项目“MyTestDLL”-》属性-》生成-》勾选“为COM互操作注册”
3 打开 AssemblyInfo.cs 文件 修改 [assembly: ComVisible(true)]
4 打开Visual Sutdio 2008 的命令提示行工具输入guidgen.exe 选择D ......

C#读写xml文件

已知有一个XML文件(bookstore.xml)如下:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
  <book genre="fantasy" ISBN="2-3631-4">
    <title>Oberon's Legacy</title>
    <author>Corets, Eva</author>
  &nb ......

HTML,XML,UML 简介

HTML,XML,UML 简介
 
HTML (HyperText Mark-up Language)超文本标记语言  是WWW的描述语言。设计HTML语言的目的是为了能把存放在一台电脑中的文本或图形与另一台电脑中的文本或图形方便地联系在一起,形成有机的整体,人们不用考虑具体信息是在当前电脑上还是在网络的其它电脑上。HTML文本是由HTML命令组成的 ......

更快的写XML的方法

我写的第一个程序中写XML的代码执行速度有些问题,改了一下,现在有所改善。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Data.SqlClient;
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号