user568164
user568164

Reputation:

XML elements to array of bool

I have the following XML

<Appointment>
    <FollowupDays>
        <boolean>true</boolean>
        <boolean>true</boolean>
        <boolean>false</boolean>
        <boolean>true</boolean>
    </FollowupDays>
</Appointment>

I want a bool[] loaded from the elements of FollowupDays. The boolean elements are are items in the array.

Thanks in advance.

Upvotes: 1

Views: 331

Answers (1)

Abdul Munim
Abdul Munim

Reputation: 19217

If you consider using XElement which is supported .NET 3 and above, you can consider using this:

XElement xElement = XElement.Load("path/to/your/xml");
bool[] followupDays = xElement
                        .Decendents("FollowupDays")
                        .First()
                        .Select(b => 
                            Convert.ToBoolean(b.Value))
                        .ToArray();

Upvotes: 2

Related Questions