Xml序列化与"True"对比和“假" [英] Xml Serialization vs. "True" and "False"

查看:128
本文介绍了Xml序列化与"True"对比和“假"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用布尔值反序列化XML文件时遇到问题.我要反序列化的源XML文件是从VB6应用程序创建的,其中所有布尔值均大写(TrueFalse).当我尝试反序列化XML时,我得到了

I'm having an issue with deserializing an XML file with boolean values. The source XML files I'm deserializing were created from a VB6 app, where all boolean values are capitalized (True, False). When I try to deserialize the XML, I'm getting a

System.FormatException: The string 'False' is not a valid Boolean value.

有没有一种方法可以忽略带有属性的大小写?

Is there a way to say ignore case with an attribute?

推荐答案

您可以将该值作为字符串读取到字符串字段中,然后有一个只读的bool字段,其中带有if语句,以返回布尔值true或false.

You could read that value as a string into a string field, then have a readonly bool field that had an if statement in it to return bool true or false.

例如(使用c#):

public bool str2bool(string str)
{
  if (str.Trim().ToUpper() == "TRUE")
      return true;
  else
      return false;
}

您可以在模板中使用它:

And you can use it in the template:

<xsl:if test="user:str2bool($mystr)">

这篇关于Xml序列化与"True"对比和“假"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆