Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deserialize boolean element with string attribute

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?????
}
like image 855
AngieM Avatar asked Jul 12 '26 20:07

AngieM


1 Answers

Try

[XmlText]
public bool ServiceValue {get;set;}
like image 84
John Saunders Avatar answered Jul 15 '26 09:07

John Saunders



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!