与反序列化字符串属性布尔元素 [英] Deserialize boolean element with string attribute
本文介绍了与反序列化字符串属性布尔元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图构建一个类,将与该XML结构映射,但无法弄清楚如何。我见过的例子在这里,我可以用[XMLTEXT]如果元素的值是一个字符串。在我的情况下,元素的值是布尔值。我应该如何构建我的服务类?
(我认为)我知道如何把服务元素的照顾:-)。这只是服务对象的数组。我只是不知道如何建设服务类
<?XML版本=1.0编码= UTF-8>?;
<配置的xmlns:XSI =http://www.w3.org/2001/XMLSchema-instance的xmlns:XSD =http://www.w3.org/2001/XMLSchema>
< MyConfigs>
<服务及GT;
<服务名称=服务名称>真< /服务>
< /服务及GT;
< / MyConfigs>
我有这样的:
[XmlArray(服务)]
[XmlArrayItem(服务)]
公共服务[]服务{搞定;组; }
和这样的:
公共类服务
{
[XmlAttribute]
公共字符串名称{;组; }
//我如何获得布尔值这里?????
}
解决方案
尝试
[XMLTEXT]
公共BOOL ServiceValue {获取;集;}
I'm trying to construct a class that would map with this XML structure, but can't figure out how. I've seen examples here where I can use [XmlText] if the element value is a string. In my case, the element value is boolean. How should I construct my "Service" class?
(I think) I know how to take care of the "Services" element :-). It's just an array of "Service" objects. I'm just not sure how to build the "Service" class.
<?xml version="1.0" encoding="utf-8"?>
<Config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MyConfigs>
<Services>
<Service Name="ServiceName">true</Service>
</Services>
</MyConfigs>
I have this:
[XmlArray("Services")]
[XmlArrayItem("Service")]
public Service[] Services { get; set; }
And this:
public class Service
{
[XmlAttribute]
public string Name { get; set; }
// How do I get the boolean value here?????
}
解决方案
Try
[XmlText]
public bool ServiceValue {get;set;}
这篇关于与反序列化字符串属性布尔元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文