amethyste,
are you trying to dynamically set the element name based on values in
your object, i.e. if the propertyName is foo and the label is set to
range, then the serialized XML is
<foo range="..." />?
First, changing the element name is only possible if you have a fixed
set of element names, but not if propertyName can hold arbitrary
strings. XML serialization is intended to be used with
strongly-structured XML data. Therefore it works best if you can express
the XML format as an XML Schema. You can change the element names either
based on the type of the serialized object:
[XmlElement( "foo", typeof(fooType))]
[XmlElement( "bar", typeof(barType))]
public foobarType propertyName;
or by using the choice construct [0].
Second, changing the attribute name dynamically only works based on the
type of the serialized type via attaching multiple attributes. There is
no equivalent to the choice construct for attributes.
If you need to be able to by more dynamic than that you must implement
IXmlSerializable [1].
HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko
[0] http://www.topxml.com/xmlserializer/choice_model_groups.asp
[1] http://msdn2.microsoft.com/library/fhd7bk0a.aspx
> -----Original Message-----
> From: amethyste [mailto:anonymous@discussions.microsoft.com]
[quoted text clipped - 45 lines]
>
> Happy new years
amethyste - 28 Dec 2004 20:28 GMT
thank you,
I suspected something like this.
I'm in the case where IXmlSerializable is the solution.
But IXmlSerializable is not officially documented. This
wories me a little bit.
>-----Original Message-----
>
[quoted text clipped - 32 lines]
>
>[0] http://www.topxml.com/xmlserializer/choice_model_groups.as
p
>[1] http://msdn2.microsoft.com/library/fhd7bk0a.aspx
>
[quoted text clipped - 49 lines]
>
>.
Mujtaba Syed - 28 Dec 2004 21:53 GMT
Hi:
Till .NET 1.1, IXmlSerializable was mostly intended for internal (MS) use.
With 2.0, IXmlSerializable is receiving more publicity and programmers will
be encouraged to use it.
For info about how to implement IXmlSerializable in 1.1:
http://dotnetified.com/PermaLink.aspx?guid=E86B447E-AA95-49B6-909F-CDA36ACF481F
Mujtaba.
> thank you,
>
[quoted text clipped - 105 lines]
> >
> >.
Christoph Schittko [MVP] - 29 Dec 2004 03:13 GMT
The .NET 2.0 documentation for IXmlSerializable is also already
available at
http://msdn2.microsoft.com/library/fhd7bk0a.aspx
HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko
> -----Original Message-----
> From: Mujtaba Syed [mailto:mujtaba@marlabs.com]
[quoted text clipped - 124 lines]
> > >
> > >.
Mujtaba Syed - 29 Dec 2004 15:31 GMT
It is not recommeded to use the GetSchema method of IXmlSerialiazable 2.0.
Instead a new attribute called [XmlSchemaProvider] is available to indicate
a static method of the type that will provide the schema.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/wsn
etfx2.asp
Mujtaba.
> The .NET 2.0 documentation for IXmlSerializable is also already
> available at
[quoted text clipped - 135 lines]
> > > >
> > > >.
amethyste - 29 Dec 2004 12:14 GMT
IXmlSerializable is still for internal use in vs 2005
béta, but this time MS gives samples!
I don't understand this anyway, why not fully document
this interface? It's just an interface after all and
runtime serialization has a full support for
customization already.
thank you
Amethyste
>-----Original Message-----
>Hi:
[quoted text clipped - 60 lines]
>> >
>> >[0]
http://www.topxml.com/xmlserializer/choice_model_groups.as
>> p
>> >[1] http://msdn2.microsoft.com/library/fhd7bk0a.aspx
[quoted text clipped - 53 lines]
>
>.