Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Serialize complex type element with simple content

Reply
Thread Tools

Serialize complex type element with simple content

 
 
Albert Jan
Guest
Posts: n/a
 
      10-04-2004
Hi,

This must be easy, but I can't find an example:

I want to automatically serialize an element with an attribute like the
following
<ClientSoftware version="(254)">MySoftware</ClientSoftware>

to a C# class.

If 'Clientsoftware' has child elements I can use something like the code
given below , but I don't know how to do this when the element has simple
content.

I appreciate any help on this subject,

Albert Jan




using System;
using System.Xml.Serialization;
namespace myns
{
public class ClientSoftwareType
{
virtual public System.String Name
{
get
{
return name
}

set
{
name = value;
}

}

[XmlAttribute ("version")]
virtual public System.String Version
{
get
{
return version;
}

set
{
this.version = value;
}

}
private System.String name;
private System.String version;
}
}












 
Reply With Quote
 
 
 
 
tom wisnowski
Guest
Posts: n/a
 
      10-05-2004
public class ClientSoftwareType
{
[XmlAttribute]
public string Version

[XmlText]
publc string Value
}

You can use properties instead of public fields, just be sure to use the
[XmlText] attribute, that is what you are looking for.

"Albert Jan" wrote:

> Hi,
>
> This must be easy, but I can't find an example:
>
> I want to automatically serialize an element with an attribute like the
> following
> <ClientSoftware version="(254)">MySoftware</ClientSoftware>
>
> to a C# class.
>
> If 'Clientsoftware' has child elements I can use something like the code
> given below , but I don't know how to do this when the element has simple
> content.
>
> I appreciate any help on this subject,
>
> Albert Jan
>
>
>
>
> using System;
> using System.Xml.Serialization;
> namespace myns
> {
> public class ClientSoftwareType
> {
> virtual public System.String Name
> {
> get
> {
> return name
> }
>
> set
> {
> name = value;
> }
>
> }
>
> [XmlAttribute ("version")]
> virtual public System.String Version
> {
> get
> {
> return version;
> }
>
> set
> {
> this.version = value;
> }
>
> }
> private System.String name;
> private System.String version;
> }
> }
>
>
>
>
>
>
>
>
>
>
>
>
>

 
Reply With Quote
 
 
 
 
Albert Jan
Guest
Posts: n/a
 
      10-05-2004
Thank you Tom,

indeed that is what I was looking for!

Albert Jan

"tom wisnowski" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> public class ClientSoftwareType
> {
> [XmlAttribute]
> public string Version
>
> [XmlText]
> publc string Value
> }
>
> You can use properties instead of public fields, just be sure to use the
> [XmlText] attribute, that is what you are looking for.
>
> "Albert Jan" wrote:
>
> > Hi,
> >
> > This must be easy, but I can't find an example:
> >
> > I want to automatically serialize an element with an attribute like the
> > following
> > <ClientSoftware version="(254)">MySoftware</ClientSoftware>
> >
> > to a C# class.
> >
> > If 'Clientsoftware' has child elements I can use something like the code
> > given below , but I don't know how to do this when the element has

simple
> > content.
> >
> > I appreciate any help on this subject,
> >
> > Albert Jan
> >
> >
> >
> >
> > using System;
> > using System.Xml.Serialization;
> > namespace myns
> > {
> > public class ClientSoftwareType
> > {
> > virtual public System.String Name
> > {
> > get
> > {
> > return name
> > }
> >
> > set
> > {
> > name = value;
> > }
> >
> > }
> >
> > [XmlAttribute ("version")]
> > virtual public System.String Version
> > {
> > get
> > {
> > return version;
> > }
> >
> > set
> > {
> > this.version = value;
> > }
> >
> > }
> > private System.String name;
> > private System.String version;
> > }
> > }
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
wsdl2java: method parameter a complex type that extends another complex type Robert Mark Bram Java 0 02-04-2007 10:06 AM
[XML Schema] Content type of complex type definition with complex content Stanimir Stamenkov XML 2 10-25-2005 10:16 AM
How do I restrict the type of a text node in a mixed, complex-type element? Chishun Kwong XML 0 03-03-2005 05:09 PM
serialize to SQL Server Blob instead of XML serialize Gordz ASP .Net 3 06-07-2004 07:46 PM
element of complex type without type="" possible? Ulf Heyder XML 1 10-28-2003 04:30 PM



Advertisments