Question

this is the XML that i'm try to deserialize. I keep getting "resultConfig xmlns=' '> was not expected."}

I tired all the solution on stackoverflow regarding this issue nothing really worked. Thank you in advance.

<?xml version="1.0" encoding="UTF-8" ?>
<resultConfig>
    <folders>
        <folder>
            <location>C:\</location>
        </folder>
        <folder>
            <location>C:\Temp</location>
        </folder>
    </folders>
    <resultClasses>
        <resultClass name="ScdExctractSqlXYZ" type="CSV">
            <resultTypeQuery>REGEX</resultTypeQuery>
            <testIdQuery>REGEX</testIdQuery>
        </resultClass>  
        <resultClass name="SubNotification" type="XML">     
            <resultTypeQuery>XPATH</resultTypeQuery>
            <testIdQuery>XPATH</testIdQuery>
            <transformation>something.xsl</transformation>      
        </resultClass>
    </resultClasses>
</resultConfig>

I declared my class object as:

namespace TestGen
{

    public class ResultClasses
    {
        [XmlRoot("resultConfig")]
        public class resultConfig
        {
            [XmlArray("folders")]
            [XmlArrayItem("folder")]
            public List<folder> folders { get; set; }

            [XmlArray("resultClasses")]
            [XmlArrayItem("resultClass")]
            public List<resultClass> classes { get; set; }
        }

        public class folder
        {
            [XmlArray("location")]
            public string location { get; set; }
        }

        public class resultClass
        {
            [XmlAttribute("name")]
            public string name { get; set; }
            [XmlAttribute("type")]
            public string type { get; set; }


            [XmlArrayItem("resultTypeQuery")]
            public string resultTypeQuery { get; set; }
            [XmlArrayItem("testIdQuery")]
            public string testIdQuery { get; set; }
            [XmlArrayItem("transformation")]
            public string transformation { get; set; }

        }       

    }

}

I then call my deserializer this way:

 using (FileStream reader = new FileStream(@"C:\ResultConfig.xml", FileMode.Open, FileAccess.Read))
 {

     XmlSerializer serializer = new XmlSerializer(typeof(ResultClasses));
     var ei = serializer.Deserialize(reader);
 }
Was it helpful?

Solution

What is the outer class ResultClasses good for? If you remove that and use new XmlSerializer(typeof(resultConfig)) it should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top