较低的“敏感性”在XMLReader和XMLSerializer上 [英] Less "sensitivity" on XMLReader and XMLSerializer

查看:66
本文介绍了较低的“敏感性”在XMLReader和XMLSerializer上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于对象的大型xml文档。我以前有一个名为Color的属性,其中包含一种颜色类型。现在我将其更改为Integer类型。会发生什么事情是第x行等加载失败。

I have a large xml document which is based on an object. I previously had a property named Color which contained a color type. Now I changed this to type Integer. What happens is that loading fails on row x etc.

 

我想知道是否有办法告诉它不那么敏感只是忽略它无法反序列化的值?例如,使用新属性的默认属性。

I wonder if there is a way to tell it to be less sensitive and just ignore values it cannot deserialize? Use default properties of new property for example.

推荐答案



Henrik,

Henrik,

我猜你的XML包含这样的内容:"< Color> Blue< / Color>" - 然后"蓝色"不能被转换为整数。这是你的问题吗?简短的回答是否定的。

I'm guessing that your XML contains something like this: "<Color>Blue</Color>" - and then "Blue" can't be casted to an integer. Is this your problem? The short answer is no.

那就是说,当你说"不太敏感"时,我不确定你的意思?什么价值的财产"颜色"如果出现反序列化错误,你会接受吗?你甚至关心"颜色"吗?属性从XML无效?



b b如果您根本不关心那么只需在该属性上放置一个忽略声明:

That said, I'm not sure what you mean when you say "less sensitive"? What value of property "Color" would you accept in case of de-serialization error? Do you even care about the "Color" property being invalid from XML?

If you don't care at all then just put a ignore declaration on that property:


public class Test
{
    [System.Xml.Serialization.XmlIgnore]
    public int Color { get; set; }
}


这篇关于较低的“敏感性”在XMLReader和XMLSerializer上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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