By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,852 Members | 955 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,852 IT Pros & Developers. It's quick & easy.

question about xml serilization

P: n/a
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
Nov 12 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a

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
-----Original Message-----
From: amethyste [mailto:an*******@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


Nov 12 '05 #2

P: n/a
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 inyour object, i.e. if the propertyName is foo and the label is set torange, then the serialized XML is

<foo range="..." />?

First, changing the element name is only possible if you have a fixedset of element names, but not if propertyName can hold arbitrarystrings. XML serialization is intended to be used with
strongly-structured XML data. Therefore it works best if you can expressthe XML format as an XML Schema. You can change the element names eitherbased 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 thetype of the serialized type via attaching multiple attributes. There isno equivalent to the choice construct for attributes.

If you need to be able to by more dynamic than that you must implementIXmlSerializable [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:an*******@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


.

Nov 12 '05 #3

P: n/a
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" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
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:an*******@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


.

Nov 12 '05 #4

P: n/a
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:mu*****@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) 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...A95-49B6-909F-
CDA36ACF481F

Mujtaba.

"amethyste" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
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:an*******@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

.

Nov 12 '05 #5

P: n/a
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:

Till .NET 1.1, IXmlSerializable was mostly intended for internal (MS) use.With 2.0, IXmlSerializable is receiving more publicity and programmers willbe encouraged to use it.
For info about how to implement IXmlSerializable in 1.1:
http://dotnetified.com/PermaLink.asp...E86B447E-AA95- 49B6-909F-CDA36ACF481F
Mujtaba.

"amethyste" <an*******@discussions.microsoft.com> wrote in messagenews:03****************************@phx.gbl...
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:an*******@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
>
>.
>

.

Nov 12 '05 #6

P: n/a
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]" <IN**********@austin.rr.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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:mu*****@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)

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...A95-49B6-909F-
CDA36ACF481F

Mujtaba.

"amethyste" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
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:an*******@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
>
>.
>


Nov 12 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.