Click here to Skip to main content
15,067,539 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have a problem and i dont know what i should do about it.

I am using XMLSerialization to write the XML like

XmlSerializer s = new XmlSerializer(typeof(Config));
                TextWriter w = new StreamWriter(ConfigFileName);
                s.Serialize(w, this);

now i want the XML to be like


and it has to an array.

I am doing like this

public string[] Extension = new string[0];

and the class like

public class Extension
        public string Extention;
        //public string Extensions;

        //public Extension()
        //  //  Extensions += Extention;
        //public Extension(string[] ThisExt)
        //    Extention += ThisExt;

Please see the commented part for more on the class.

Now as i write the Xml it gives me the output like


I know i have to implement the class to achieve this but when i am trying to write the XML it says it cannot write the xml as only non parametrized constructor need. Is it like serialization can be done only for default constructor and not for the user defined constructor for a class.

This is one issue and the other issue is,

HOW TO DO IT. Please reply. Thanks in Adv.
Updated 15-Feb-10 2:45am

Ummmm, shouldn't the name of the property in the class be the name of the XML element/attribute you want?
That is true it has to be like

<pre lang="cs">XmlArrayAttribute(&quot;Extensions&quot;)]
public Extension[] Extension = new string[0];</pre>

and the class has to be like

<pre lang="cs">public class Extension
public string Extention;
public string Extensions;

public Extension()
// Extensions += Extention;
public Extension(string[] ThisExt)
Extention += ThisExt;

but when i write the XML its comes out to be like

why it is like this

i need it to be like

</Extension >

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900