Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Please help! XML Deserialization to Class issue in C#

  • 17-09-2010 1:33pm
    #1
    Registered Users, Registered Users 2 Posts: 250 ✭✭


    This is the XML I am trying to parse:
    <?xml version="1.0" ?> 
    <result>
    	<context>W3Svc</context> 
    	<command>EnumSites</command> 
    	<status>success</status> 
    	<sitecount>3</sitecount> 
    	<sites>
    		<site>
    			<id>1</id> 
    			<state>Stopped</state> 
    			<comment>Default Web Site</comment> 
    		</site>
    		<site>
    			<id>2</id> 
    			<state>Started</state> 
    			<comment>iisman</comment> 
    		</site>
    		<site>
    			<id>3</id> 
    			<state>Stopped</state> 
    			<comment>test2</comment> 
    		</site>
    	</sites>
    </result>
    

    and this is my class:
    public class Site
        {
            private int __id = 0;
            [XmlElement(ElementName = "id")]
            public int Id { get { return __id; } set { __id = value; } }
        }
    
        [XmlRoot(ElementName = "result")]
        public class EnumSitesClass : ResponseHeader
        {
            private int __siteCount = 0;
            [XmlElement(ElementName = "sitecount")]
            public int SiteCount { get { return __siteCount; } set { __siteCount = value; } }
    
            [XmlArray("Sites")]
            [XmlArrayItem("Site", typeof(Site))]
            public Site[] SiteArray;
        }
    
        public class EnumSites
        {
            private EnumSitesClass m_response = null;
    
            public EnumSitesClass Get { get { return m_response; } }
    
            public EnumSites(string hostName, int timeOut)
            {
                EnumSitesClass test = new EnumSitesClass();
                HTTP http = new HTTP(timeOut);
    
                Interface adsi = new Interface(hostName);
    
                string interfaceUrl = adsi.GetInterfaceUrl(InterfaceCommandUrl.EnumSites, Context.W3Svc, HttpConnType.http);
                string ret = http.GetHttp(interfaceUrl);
    
                StringReader reader = new StringReader(ret);
                XmlSerializer s = new XmlSerializer(typeof(EnumSitesClass));
                m_response = (EnumSitesClass)s.Deserialize(reader);
            }
        }
    }
    
    EnumSites es = new EnumSites("127.0.0.1", 6000);
                EnumSitesClass esc = es.Get;
    
    esc.SiteArray remains null for some bizarre reason after execution. Am I going mad???

    Any help would be appreciated.


Comments

  • Registered Users, Registered Users 2 Posts: 11,989 ✭✭✭✭Giblet


    You're going to kick yourself.
    [XmlArray("sites")]
    [XmlArrayItem("site", typeof(Site))]
    

    Case sensitive...

    Happens to us all :)


  • Registered Users, Registered Users 2 Posts: 250 ✭✭ikoonman


    Now I feel like an idiot - LOL - thanks for your help.


Advertisement