Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / December 2004

Tip: Looking for answers? Try searching our database.

question about xml serilization

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
amethyste - 28 Dec 2004 13:15 GMT
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] - 28 Dec 2004 16:31 GMT
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]
>
>.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.