G
Guest
Hi
I'm currently having trouble serializing an object to Xml, in the format I
need.
Below is the object definition.
-------------------------------
[Serializable]
public class Folders
{
protected List<PathString> _include;
protected List<PathString> _exclude;
public Folders()
{
_include = new List<PathString>();
_exclude = new List<PathString>();
}
[XmlArrayItem("Include")]
public List<PathString> Include
{
get { return _include; }
set { _include = value; }
}
[XmlArrayItem(ElementName="Exclude",Type=typeof(PathString))]
public List<PathString> Excludes
{
get { return _exclude; }
set { _exclude = value; }
}
}
[Serializable]
public class PathString
{
protected string _path;
[XmlAttribute]
public string Path
{
get { return _path; }
set { _path = value; }
}
public PathString()
{
}
public PathString(string path)
{
_path = path;
}
}
--------------------------
From these objects, I want my Xml output to look like :
<Folders>
<Include Path="Path1"/>
<Include Path="Path2"/>
<Exclude Path="LessTrodden"/>
</Folders>
However, I am having trouble getting the correct output.
The code above produces the following :
<Folders>
<Include>
<Include Path="Path1"/>
<Include Path="Path2"/>
</Include>
<Excludes>
<Exclude Path="LessTrodden"/>
</Excludes>
</Folders>
I want to use List (or IList) as I want to bind my object to a DevExpress
TreeList
Does anyone have an idea of how I can get my required output ?
Cheers
Ged
I'm currently having trouble serializing an object to Xml, in the format I
need.
Below is the object definition.
-------------------------------
[Serializable]
public class Folders
{
protected List<PathString> _include;
protected List<PathString> _exclude;
public Folders()
{
_include = new List<PathString>();
_exclude = new List<PathString>();
}
[XmlArrayItem("Include")]
public List<PathString> Include
{
get { return _include; }
set { _include = value; }
}
[XmlArrayItem(ElementName="Exclude",Type=typeof(PathString))]
public List<PathString> Excludes
{
get { return _exclude; }
set { _exclude = value; }
}
}
[Serializable]
public class PathString
{
protected string _path;
[XmlAttribute]
public string Path
{
get { return _path; }
set { _path = value; }
}
public PathString()
{
}
public PathString(string path)
{
_path = path;
}
}
--------------------------
From these objects, I want my Xml output to look like :
<Folders>
<Include Path="Path1"/>
<Include Path="Path2"/>
<Exclude Path="LessTrodden"/>
</Folders>
However, I am having trouble getting the correct output.
The code above produces the following :
<Folders>
<Include>
<Include Path="Path1"/>
<Include Path="Path2"/>
</Include>
<Excludes>
<Exclude Path="LessTrodden"/>
</Excludes>
</Folders>
I want to use List (or IList) as I want to bind my object to a DevExpress
TreeList
Does anyone have an idea of how I can get my required output ?
Cheers
Ged