F.Mayis
July 12th, 2007, 09:28 AM
Hi all,
I'm quite new to C# and I have some Xml serialization indeed.
I have objects define as follows :
public class ObjSub{
//some data
public string mySubStr;
public int mySubInt;
}
public class ObjMain{
//some data
public string myStr;
public int myInt;
public ObjSub subObj = new ObjSub();
}
I deserialize my objects from Xml file:
public static SchedulerTemplateFile Load(string fileName)
{
using (StreamReader sw = new StreamReader(fileName))
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(ObjMain));
xmlSerializer.UnknownAttribute += new XmlAttributeEventHandler(Serializer_UnknownAttribute);
return (ObjMain)xmlSerializer.Deserialize(sw);
}
}
See that I use An UnknowAttribute event handler to get and store unknown attribute if needed.
Now here is the problem:
The Unknown attribute handler works well for ObjMain, but is nevver called for ObjSub.
if for the ObjSub I have the node
<ObjSub id="1">
<mySubStr>"SubStr"</mySubStr>
<mySubInt>"10"</mySubInt>
</ObjSub>
I would never have the event telling me about "id" attribute.
Does anyone already experienced that.
Many Thanks
I'm quite new to C# and I have some Xml serialization indeed.
I have objects define as follows :
public class ObjSub{
//some data
public string mySubStr;
public int mySubInt;
}
public class ObjMain{
//some data
public string myStr;
public int myInt;
public ObjSub subObj = new ObjSub();
}
I deserialize my objects from Xml file:
public static SchedulerTemplateFile Load(string fileName)
{
using (StreamReader sw = new StreamReader(fileName))
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(ObjMain));
xmlSerializer.UnknownAttribute += new XmlAttributeEventHandler(Serializer_UnknownAttribute);
return (ObjMain)xmlSerializer.Deserialize(sw);
}
}
See that I use An UnknowAttribute event handler to get and store unknown attribute if needed.
Now here is the problem:
The Unknown attribute handler works well for ObjMain, but is nevver called for ObjSub.
if for the ObjSub I have the node
<ObjSub id="1">
<mySubStr>"SubStr"</mySubStr>
<mySubInt>"10"</mySubInt>
</ObjSub>
I would never have the event telling me about "id" attribute.
Does anyone already experienced that.
Many Thanks