[XmlText]
, like so:
using System;
using System.Xml.Serialization;
[Serializable, XmlRoot("myElement")]
public class MyType {
[XmlAttribute("name")]
public string Name {get;set;}
[XmlText]
public string Text {get;set;}
}
static class Program {
static void Main() {
new XmlSerializer(typeof(MyType)).Serialize(Console.Out,
new MyType { Name = "foo", Text = "bar" });
}
}
Related Contents:
- Why XML-Serializable class need a parameterless constructor
- Serialize an object to XML
- Convert XML String to Object
- How do you serialize a string as CDATA using XmlSerializer?
- Is it possible to deserialize XML into List?
- Xml serialization – Hide null values
- XML Serialization and namespace prefixes
- {” was not expected.} Deserializing Twitter XML
- Using XmlSerializer to serialize derived classes
- Using StringWriter for XML Serialization
- Omitting all xsi and xsd namespaces when serializing an object in .NET?
- What is the best way to parse (big) XML in C# Code?
- ShouldSerialize*() vs *Specified Conditional Serialization Pattern
- XmlSerializer giving FileNotFoundException at constructor
- Serialize an object to string
- XML Serialization and Inherited Types
- XML Serialize generic list of serializable objects
- Can I make XmlSerializer ignore the namespace on deserialization?
- Most elegant XML serialization of Color structure
- Why are properties without a setter not serialized
- .NET XML serialization gotchas? [closed]
- Serialize Property as Xml Attribute in Element
- .net XML Serialization – Storing Reference instead of Object Copy
- How do you find out when you’ve been loaded via XML Serialization?
- Serializing an object as UTF-8 XML in .NET
- Deserializing into a List without a container element in XML
- How to decode string to XML string in C#
- Why isn’t my public property serialized by the XmlSerializer?
- How to add XmlInclude attribute dynamically
- Generating XML file using XSD file
- Serialize a Bitmap in C#/.NET to XML
- How can I make the xmlserializer only serialize plain xml?
- How do I map XML to C# objects
- Data Contract Serializer – How to omit the outer element of a collection
- Deciding on when to use XmlDocument vs XmlReader
- How can I serialize internal classes using XmlSerializer?
- Force XmlSerializer to serialize DateTime as ‘YYYY-MM-DD hh:mm:ss’
- When a class is inherited from List, XmlSerializer doesn’t serialize other attributes
- How to XML-serialize a dictionary
- XmlSerializer serialize generic List of interface
- What is MyAssembly.XmlSerializers.dll generated for?
- XmlSerialize a custom collection with an Attribute
- Excluding some properties during serialization without changing the original class
- Checking if an object is a number
- Suppress Null Value Types from Being Emitted by XmlSerializer
- using XmlArrayItem attribute without XmlArray on Serializable C# class
- How to add attributes for C# XML Serialization
- Convert Dataset to XML
- Ignore a property during xml serialization but not during deserialization
- How to rename XML attribute that generated after serializing List of objects