Connecting Tech Pros Worldwide Forums | Help | Site Map

question about xml serilization

amethyste
Guest
 
Posts: n/a
#1: Nov 12 '05
hello,

This is my sample (simplified):

public class Binom
{
[XmlAttribute("range")]
public string _Value;

[XmlAttribute("name")]
public string Label;
}

public class Property
{
[XmlAttribute("name")]
public string propertyName;

public Binom DefaultAttribute;
}


Property serialize as:

<Properties name="foo">
<DefaultAttribute value="123456789" name="range" />
</Properties >

Is is possible to get rather:

<foo range="123456789"/>

or eventualy:

<Properties name="foo">
<DefaultAttribute range="123456789" />
</Properties >

Just using the default Xml serailization?

Thank you

Happy new years

Christoph Schittko [MVP]
Guest
 
Posts: n/a
#2: Nov 12 '05

re: question about xml serilization



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/...del_groups.asp
[1] http://msdn2.microsoft.com/library/fhd7bk0a.aspx
[color=blue]
> -----Original Message-----
> From: amethyste [mailto:anonymous@discussions.microsoft.com]
> Posted At: Tuesday, December 28, 2004 7:16 AM
> Posted To: microsoft.public.dotnet.xml
> Conversation: question about xml serilization
> Subject: question about xml serilization
>
> hello,
>
> This is my sample (simplified):
>
> public class Binom
> {
> [XmlAttribute("range")]
> public string _Value;
>
> [XmlAttribute("name")]
> public string Label;
> }
>
> public class Property
> {
> [XmlAttribute("name")]
> public string propertyName;
>
> public Binom DefaultAttribute;
> }
>
>
> Property serialize as:
>
> <Properties name="foo">
> <DefaultAttribute value="123456789" name="range" />
> </Properties >
>
> Is is possible to get rather:
>
> <foo range="123456789"/>
>
> or eventualy:
>
> <Properties name="foo">
> <DefaultAttribute range="123456789" />
> </Properties >
>
> Just using the default Xml serailization?
>
> Thank you
>
> Happy new years[/color]

amethyste
Guest
 
Posts: n/a
#3: Nov 12 '05

re: question about xml serilization


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.

[color=blue]
>-----Original Message-----
>
>amethyste,
>
>are you trying to dynamically set the element name based[/color]
on values in[color=blue]
>your object, i.e. if the propertyName is foo and the[/color]
label is set to[color=blue]
>range, then the serialized XML is
>
><foo range="..." />?
>
>First, changing the element name is only possible if you[/color]
have a fixed[color=blue]
>set of element names, but not if propertyName can hold[/color]
arbitrary[color=blue]
>strings. XML serialization is intended to be used with
>strongly-structured XML data. Therefore it works best if[/color]
you can express[color=blue]
>the XML format as an XML Schema. You can change the[/color]
element names either[color=blue]
>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[/color]
works based on the[color=blue]
>type of the serialized type via attaching multiple[/color]
attributes. There is[color=blue]
>no equivalent to the choice construct for attributes.
>
>If you need to be able to by more dynamic than that you[/color]
must implement[color=blue]
>IXmlSerializable [1].
>
>HTH,
>Christoph Schittko
>MVP XML
>http://weblogs.asp.net/cschittko
>
>
>
>[0][/color]
http://www.topxml.com/xmlserializer/...odel_groups.as
p[color=blue]
>[1] http://msdn2.microsoft.com/library/fhd7bk0a.aspx
>[color=green]
>> -----Original Message-----
>> From: amethyste[/color][/color]
[mailto:anonymous@discussions.microsoft.com][color=blue][color=green]
>> Posted At: Tuesday, December 28, 2004 7:16 AM
>> Posted To: microsoft.public.dotnet.xml
>> Conversation: question about xml serilization
>> Subject: question about xml serilization
>>
>> hello,
>>
>> This is my sample (simplified):
>>
>> public class Binom
>> {
>> [XmlAttribute("range")]
>> public string _Value;
>>
>> [XmlAttribute("name")]
>> public string Label;
>> }
>>
>> public class Property
>> {
>> [XmlAttribute("name")]
>> public string propertyName;
>>
>> public Binom DefaultAttribute;
>> }
>>
>>
>> Property serialize as:
>>
>> <Properties name="foo">
>> <DefaultAttribute value="123456789" name="range" />
>> </Properties >
>>
>> Is is possible to get rather:
>>
>> <foo range="123456789"/>
>>
>> or eventualy:
>>
>> <Properties name="foo">
>> <DefaultAttribute range="123456789" />
>> </Properties >
>>
>> Just using the default Xml serailization?
>>
>> Thank you
>>
>> Happy new years[/color]
>
>.
>[/color]
Mujtaba Syed
Guest
 
Posts: n/a
#4: Nov 12 '05

re: question about xml serilization


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.asp...F-CDA36ACF481F

Mujtaba.

"amethyste" <anonymous@discussions.microsoft.com> wrote in message
news:038601c4ed1b$db33ee10$a601280a@phx.gbl...[color=blue]
> 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.
>
>[color=green]
> >-----Original Message-----
> >
> >amethyste,
> >
> >are you trying to dynamically set the element name based[/color]
> on values in[color=green]
> >your object, i.e. if the propertyName is foo and the[/color]
> label is set to[color=green]
> >range, then the serialized XML is
> >
> ><foo range="..." />?
> >
> >First, changing the element name is only possible if you[/color]
> have a fixed[color=green]
> >set of element names, but not if propertyName can hold[/color]
> arbitrary[color=green]
> >strings. XML serialization is intended to be used with
> >strongly-structured XML data. Therefore it works best if[/color]
> you can express[color=green]
> >the XML format as an XML Schema. You can change the[/color]
> element names either[color=green]
> >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[/color]
> works based on the[color=green]
> >type of the serialized type via attaching multiple[/color]
> attributes. There is[color=green]
> >no equivalent to the choice construct for attributes.
> >
> >If you need to be able to by more dynamic than that you[/color]
> must implement[color=green]
> >IXmlSerializable [1].
> >
> >HTH,
> >Christoph Schittko
> >MVP XML
> >http://weblogs.asp.net/cschittko
> >
> >
> >
> >[0][/color]
> http://www.topxml.com/xmlserializer/...odel_groups.as
> p[color=green]
> >[1] http://msdn2.microsoft.com/library/fhd7bk0a.aspx
> >[color=darkred]
> >> -----Original Message-----
> >> From: amethyste[/color][/color]
> [mailto:anonymous@discussions.microsoft.com][color=green][color=darkred]
> >> Posted At: Tuesday, December 28, 2004 7:16 AM
> >> Posted To: microsoft.public.dotnet.xml
> >> Conversation: question about xml serilization
> >> Subject: question about xml serilization
> >>
> >> hello,
> >>
> >> This is my sample (simplified):
> >>
> >> public class Binom
> >> {
> >> [XmlAttribute("range")]
> >> public string _Value;
> >>
> >> [XmlAttribute("name")]
> >> public string Label;
> >> }
> >>
> >> public class Property
> >> {
> >> [XmlAttribute("name")]
> >> public string propertyName;
> >>
> >> public Binom DefaultAttribute;
> >> }
> >>
> >>
> >> Property serialize as:
> >>
> >> <Properties name="foo">
> >> <DefaultAttribute value="123456789" name="range" />
> >> </Properties >
> >>
> >> Is is possible to get rather:
> >>
> >> <foo range="123456789"/>
> >>
> >> or eventualy:
> >>
> >> <Properties name="foo">
> >> <DefaultAttribute range="123456789" />
> >> </Properties >
> >>
> >> Just using the default Xml serailization?
> >>
> >> Thank you
> >>
> >> Happy new years[/color]
> >
> >.
> >[/color][/color]


Christoph Schittko [MVP]
Guest
 
Posts: n/a
#5: Nov 12 '05

re: question about xml serilization


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

[color=blue]
> -----Original Message-----
> From: Mujtaba Syed [mailto:mujtaba@marlabs.com]
> Posted At: Tuesday, December 28, 2004 3:53 PM
> Posted To: microsoft.public.dotnet.xml
> Conversation: question about xml serilization
> Subject: Re: question about xml serilization
>
> Hi:
>
> Till .NET 1.1, IXmlSerializable was mostly intended for internal (MS)[/color]
use.[color=blue]
> 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.asp...A95-49B6-909F-
> CDA36ACF481F
>
> Mujtaba.
>
> "amethyste" <anonymous@discussions.microsoft.com> wrote in message
> news:038601c4ed1b$db33ee10$a601280a@phx.gbl...[color=green]
> > 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.
> >
> >[color=darkred]
> > >-----Original Message-----
> > >
> > >amethyste,
> > >
> > >are you trying to dynamically set the element name based[/color]
> > on values in[color=darkred]
> > >your object, i.e. if the propertyName is foo and the[/color]
> > label is set to[color=darkred]
> > >range, then the serialized XML is
> > >
> > ><foo range="..." />?
> > >
> > >First, changing the element name is only possible if you[/color]
> > have a fixed[color=darkred]
> > >set of element names, but not if propertyName can hold[/color]
> > arbitrary[color=darkred]
> > >strings. XML serialization is intended to be used with
> > >strongly-structured XML data. Therefore it works best if[/color]
> > you can express[color=darkred]
> > >the XML format as an XML Schema. You can change the[/color]
> > element names either[color=darkred]
> > >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[/color]
> > works based on the[color=darkred]
> > >type of the serialized type via attaching multiple[/color]
> > attributes. There is[color=darkred]
> > >no equivalent to the choice construct for attributes.
> > >
> > >If you need to be able to by more dynamic than that you[/color]
> > must implement[color=darkred]
> > >IXmlSerializable [1].
> > >
> > >HTH,
> > >Christoph Schittko
> > >MVP XML
> > >http://weblogs.asp.net/cschittko
> > >
> > >
> > >
> > >[0][/color]
> > http://www.topxml.com/xmlserializer/...odel_groups.as
> > p[color=darkred]
> > >[1] http://msdn2.microsoft.com/library/fhd7bk0a.aspx
> > >
> > >> -----Original Message-----
> > >> From: amethyste[/color]
> > [mailto:anonymous@discussions.microsoft.com][color=darkred]
> > >> Posted At: Tuesday, December 28, 2004 7:16 AM
> > >> Posted To: microsoft.public.dotnet.xml
> > >> Conversation: question about xml serilization
> > >> Subject: question about xml serilization
> > >>
> > >> hello,
> > >>
> > >> This is my sample (simplified):
> > >>
> > >> public class Binom
> > >> {
> > >> [XmlAttribute("range")]
> > >> public string _Value;
> > >>
> > >> [XmlAttribute("name")]
> > >> public string Label;
> > >> }
> > >>
> > >> public class Property
> > >> {
> > >> [XmlAttribute("name")]
> > >> public string propertyName;
> > >>
> > >> public Binom DefaultAttribute;
> > >> }
> > >>
> > >>
> > >> Property serialize as:
> > >>
> > >> <Properties name="foo">
> > >> <DefaultAttribute value="123456789" name="range" />
> > >> </Properties >
> > >>
> > >> Is is possible to get rather:
> > >>
> > >> <foo range="123456789"/>
> > >>
> > >> or eventualy:
> > >>
> > >> <Properties name="foo">
> > >> <DefaultAttribute range="123456789" />
> > >> </Properties >
> > >>
> > >> Just using the default Xml serailization?
> > >>
> > >> Thank you
> > >>
> > >> Happy new years
> > >
> > >.
> > >[/color][/color][/color]


amethyste
Guest
 
Posts: n/a
#6: Nov 12 '05

re: question about xml serilization


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
[color=blue]
>-----Original Message-----
>Hi:
>
>Till .NET 1.1, IXmlSerializable was mostly intended for [/color]
internal (MS) use.[color=blue]
>With 2.0, IXmlSerializable is receiving more publicity [/color]
and programmers will[color=blue]
>be encouraged to use it.
>For info about how to implement IXmlSerializable in 1.1:
>http://dotnetified.com/PermaLink.asp...E86B447E-AA95-[/color]
49B6-909F-CDA36ACF481F[color=blue]
>
>Mujtaba.
>
>"amethyste" <anonymous@discussions.microsoft.com> wrote [/color]
in message[color=blue]
>news:038601c4ed1b$db33ee10$a601280a@phx.gbl...[color=green]
>> 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.
>>
>>[color=darkred]
>> >-----Original Message-----
>> >
>> >amethyste,
>> >
>> >are you trying to dynamically set the element name [/color][/color][/color]
based[color=blue][color=green]
>> on values in[color=darkred]
>> >your object, i.e. if the propertyName is foo and the[/color]
>> label is set to[color=darkred]
>> >range, then the serialized XML is
>> >
>> ><foo range="..." />?
>> >
>> >First, changing the element name is only possible if [/color][/color][/color]
you[color=blue][color=green]
>> have a fixed[color=darkred]
>> >set of element names, but not if propertyName can hold[/color]
>> arbitrary[color=darkred]
>> >strings. XML serialization is intended to be used with
>> >strongly-structured XML data. Therefore it works best [/color][/color][/color]
if[color=blue][color=green]
>> you can express[color=darkred]
>> >the XML format as an XML Schema. You can change the[/color]
>> element names either[color=darkred]
>> >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[/color]
>> works based on the[color=darkred]
>> >type of the serialized type via attaching multiple[/color]
>> attributes. There is[color=darkred]
>> >no equivalent to the choice construct for attributes.
>> >
>> >If you need to be able to by more dynamic than that [/color][/color][/color]
you[color=blue][color=green]
>> must implement[color=darkred]
>> >IXmlSerializable [1].
>> >
>> >HTH,
>> >Christoph Schittko
>> >MVP XML
>> >http://weblogs.asp.net/cschittko
>> >
>> >
>> >
>> >[0][/color]
>> [/color][/color]
http://www.topxml.com/xmlserializer/...odel_groups.as[color=blue][color=green]
>> p[color=darkred]
>> >[1] http://msdn2.microsoft.com/library/fhd7bk0a.aspx
>> >
>> >> -----Original Message-----
>> >> From: amethyste[/color]
>> [mailto:anonymous@discussions.microsoft.com][color=darkred]
>> >> Posted At: Tuesday, December 28, 2004 7:16 AM
>> >> Posted To: microsoft.public.dotnet.xml
>> >> Conversation: question about xml serilization
>> >> Subject: question about xml serilization
>> >>
>> >> hello,
>> >>
>> >> This is my sample (simplified):
>> >>
>> >> public class Binom
>> >> {
>> >> [XmlAttribute("range")]
>> >> public string _Value;
>> >>
>> >> [XmlAttribute("name")]
>> >> public string Label;
>> >> }
>> >>
>> >> public class Property
>> >> {
>> >> [XmlAttribute("name")]
>> >> public string propertyName;
>> >>
>> >> public Binom DefaultAttribute;
>> >> }
>> >>
>> >>
>> >> Property serialize as:
>> >>
>> >> <Properties name="foo">
>> >> <DefaultAttribute value="123456789" name="range" />
>> >> </Properties >
>> >>
>> >> Is is possible to get rather:
>> >>
>> >> <foo range="123456789"/>
>> >>
>> >> or eventualy:
>> >>
>> >> <Properties name="foo">
>> >> <DefaultAttribute range="123456789" />
>> >> </Properties >
>> >>
>> >> Just using the default Xml serailization?
>> >>
>> >> Thank you
>> >>
>> >> Happy new years
>> >
>> >.
>> >[/color][/color]
>
>
>.
>[/color]
Mujtaba Syed
Guest
 
Posts: n/a
#7: Nov 12 '05

re: question about xml serilization


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/de...l/wsnetfx2.asp

Mujtaba.

"Christoph Schittko [MVP]" <INVALIDEMAIL@austin.rr.com> wrote in message
news:%23WkklRV7EHA.3700@tk2msftngp13.phx.gbl...[color=blue]
> 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
>
>[color=green]
> > -----Original Message-----
> > From: Mujtaba Syed [mailto:mujtaba@marlabs.com]
> > Posted At: Tuesday, December 28, 2004 3:53 PM
> > Posted To: microsoft.public.dotnet.xml
> > Conversation: question about xml serilization
> > Subject: Re: question about xml serilization
> >
> > Hi:
> >
> > Till .NET 1.1, IXmlSerializable was mostly intended for internal (MS)[/color]
> use.[color=green]
> > 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.asp...A95-49B6-909F-
> > CDA36ACF481F
> >
> > Mujtaba.
> >
> > "amethyste" <anonymous@discussions.microsoft.com> wrote in message
> > news:038601c4ed1b$db33ee10$a601280a@phx.gbl...[color=darkred]
> > > 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-----
> > > >
> > > >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/...odel_groups.as
> > > p
> > > >[1] http://msdn2.microsoft.com/library/fhd7bk0a.aspx
> > > >
> > > >> -----Original Message-----
> > > >> From: amethyste
> > > [mailto:anonymous@discussions.microsoft.com]
> > > >> Posted At: Tuesday, December 28, 2004 7:16 AM
> > > >> Posted To: microsoft.public.dotnet.xml
> > > >> Conversation: question about xml serilization
> > > >> Subject: question about xml serilization
> > > >>
> > > >> hello,
> > > >>
> > > >> This is my sample (simplified):
> > > >>
> > > >> public class Binom
> > > >> {
> > > >> [XmlAttribute("range")]
> > > >> public string _Value;
> > > >>
> > > >> [XmlAttribute("name")]
> > > >> public string Label;
> > > >> }
> > > >>
> > > >> public class Property
> > > >> {
> > > >> [XmlAttribute("name")]
> > > >> public string propertyName;
> > > >>
> > > >> public Binom DefaultAttribute;
> > > >> }
> > > >>
> > > >>
> > > >> Property serialize as:
> > > >>
> > > >> <Properties name="foo">
> > > >> <DefaultAttribute value="123456789" name="range" />
> > > >> </Properties >
> > > >>
> > > >> Is is possible to get rather:
> > > >>
> > > >> <foo range="123456789"/>
> > > >>
> > > >> or eventualy:
> > > >>
> > > >> <Properties name="foo">
> > > >> <DefaultAttribute range="123456789" />
> > > >> </Properties >
> > > >>
> > > >> Just using the default Xml serailization?
> > > >>
> > > >> Thank you
> > > >>
> > > >> Happy new years
> > > >
> > > >.
> > > >[/color][/color]
>
>[/color]


Closed Thread