3

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?????
}
John Saunders
  • 160,644
  • 26
  • 247
  • 397
AngieM
  • 735
  • 6
  • 27
  • What programming language are you working with? Can you post more of the XML tree? – eabraham Aug 03 '12 at 15:08
  • I updated the post. I'm using C#. I have other elements in the XML tree, but I only need help constructing that particular boolean element with a string attribute. Thanks! – AngieM Aug 03 '12 at 15:13
  • So you want to read the XML and initialize class instances based upon what XML nodes are encountered in a tree traversal? – eabraham Aug 03 '12 at 15:18
  • Yes. I updated the post with more info on what I've got and what I'm stilling missing. Hope that helps clarify it. Thanks! – AngieM Aug 03 '12 at 15:21
  • Have you looked into using an out-of-the-box config file? If you want a bit more structure, you can build out a [custom configuration section](http://msdn.microsoft.com/en-us/library/2tw134k3.aspx) – Steve Konves Aug 03 '12 at 15:44

1 Answers1

3

Try

[XmlText]
public bool ServiceValue {get;set;}
John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • That works!!! Somehow I just presumed that [XmlText] is meant for string values only. Duh! Thanks so much for your help :). – AngieM Aug 03 '12 at 16:14