Serialization & Deserialization
- From: "yuriy_zubarev" <yuriy_zubarev@xxxxxxxx>
- Date: 15 Sep 2005 18:42:15 -0700
Greetings,
Let's say I have a simple class:
namespace Com.Company.Group
{
[XmlRoot("factory")]
public class Factory
{
protected ArrayList widgets;
[
XmlArray("widgets"),
XmlArrayItem("widget", typeof(Widget))
]
public ArrayList Widgets
{
get { return this.widgets; }
set { this.widget= value; }
}
}
}
When an instance of Factory class gets serialized (using XmlSerializer)
the following XML is produced:
<?xml version="1.0" encoding="utf-8"?>
<factory xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<widgets>
<widget xsi:type="WidgetA">
</widget>
<widget xsi:type="WidgetB">
</widget>
</widgets>
</factory>
I see a problem here. xsi:type for <widget> doesn't include namespace.
I would expect something like:
<widget xsi:type="Com.Company.Group.WidgetA"/>
What if I have classes with the same name but from different
namespaces? I know that both XmlArray and XmlArrayItem accept
"Namespace" parameter but it's not an option here as subclasses for
Widget may come from different namespaces (and different DLL's). If I
specify Namespace for a certain widget class, it gets ignored by
XmlArray, for example:
[XmlRoot("widget", Namespace="urn:com.company.unit")]
public class WidgetX: Widget
{
}
Any way to have xsi:type containing a full type description like
"Com.Company.Group.WidgetA" instead of just "WidgetA"?
Thanks,
Yuriy
.
- Follow-Ups:
- Re: Serialization & Deserialization
- From: yuriy_zubarev
- Re: Serialization & Deserialization
- Prev by Date: Re: DTD and XmlReaderSettings
- Next by Date: Re: Is using XmlSerializer the right choice?
- Previous by thread: Re: The URI prefix is not recognized.
- Next by thread: Re: Serialization & Deserialization
- Index(es):
Relevant Pages
|