EDN Admin
Well-known member
Hello All,
I have the following class structure:
<pre lang="x-c# [XmlType("person")]
[DataContract(Name = "person")]
public class Person
{
private string _firstName;
private string _lastName;
[XmlElement(ElementName = "firstName")]
[DataMember]
public string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}
[XmlElement(ElementName = "lastName")]
[DataMember]
public string LastName
{
get { return _lastName; }
set { _lastName = value; }
}
}[/code]
And when it gets deserialized, I get this:
<pre lang="x-xml <community xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema
<people>
<firstName>Arnold</firstName>
<lastName>Rimmer</lastName>
</people>
<people>
<firstName>Dave</firstName>
<lastName>Lister</lastName>
</people>
</community>[/code]
<br/>
But what I want is this:
<pre lang="x-xml <community xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema
<people>
<person>
<firstName>Arnold</firstName>
<lastName>Rimmer</lastName>
</person>
</people>
<people>
<person>
<firstName>Dave</firstName>
<lastName>Lister</lastName>
</person>
</people>
</community>[/code]
Basically Id like to have the <person> node called out. I am using WCF class convenstion for a MVC service to deserialize to a client via XML and deserializing via the following method:
<pre lang="x-c# using (MemoryStream stream = new MemoryStream(500))
{
using (var xmlWriter = XmlTextWriter.Create(stream, new XmlWriterSettings()
{
OmitXmlDeclaration = true,
Encoding = UTF8,
Indent = true
}))
{
new XmlSerializer(typeof(T), IncludedTypes).Serialize(xmlWriter, this.Data);
}
new ContentResult
{
ContentType = "application/vnd.wageworks.ezreceipts+xml; version=1.0",
Content = UTF8.GetString(stream.ToArray()),
ContentEncoding = UTF8
}
.ExecuteResult(context);
} [/code]
View the full article
I have the following class structure:
<pre lang="x-c# [XmlType("person")]
[DataContract(Name = "person")]
public class Person
{
private string _firstName;
private string _lastName;
[XmlElement(ElementName = "firstName")]
[DataMember]
public string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}
[XmlElement(ElementName = "lastName")]
[DataMember]
public string LastName
{
get { return _lastName; }
set { _lastName = value; }
}
}[/code]
And when it gets deserialized, I get this:
<pre lang="x-xml <community xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema
<people>
<firstName>Arnold</firstName>
<lastName>Rimmer</lastName>
</people>
<people>
<firstName>Dave</firstName>
<lastName>Lister</lastName>
</people>
</community>[/code]
<br/>
But what I want is this:
<pre lang="x-xml <community xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema
<people>
<person>
<firstName>Arnold</firstName>
<lastName>Rimmer</lastName>
</person>
</people>
<people>
<person>
<firstName>Dave</firstName>
<lastName>Lister</lastName>
</person>
</people>
</community>[/code]
Basically Id like to have the <person> node called out. I am using WCF class convenstion for a MVC service to deserialize to a client via XML and deserializing via the following method:
<pre lang="x-c# using (MemoryStream stream = new MemoryStream(500))
{
using (var xmlWriter = XmlTextWriter.Create(stream, new XmlWriterSettings()
{
OmitXmlDeclaration = true,
Encoding = UTF8,
Indent = true
}))
{
new XmlSerializer(typeof(T), IncludedTypes).Serialize(xmlWriter, this.Data);
}
new ContentResult
{
ContentType = "application/vnd.wageworks.ezreceipts+xml; version=1.0",
Content = UTF8.GetString(stream.ToArray()),
ContentEncoding = UTF8
}
.ExecuteResult(context);
} [/code]
View the full article