There is not an attribute that will do that. Its not common to mix element documentation with the xml data. Usually, you want to document your xml schema with an xsd document or some other means.
That being said, here is how you could do it. You'd need to change the ISBN property from a string to a custom type that has a friendlyName property that you can serialize.
public class Book
{
public string Title { get; set; }
public ISBN ISBN { get; set; }
}
public class ISBN
{
[XmlText]
public string value { get; set; }
[XmlAttribute]
public string friendlyName { get; set; }
}
The following will serialize exactly like what you have in your question.
Book b = new Book
{
Title = "To Kill a Mockingbird",
ISBN = new ISBN
{
value = "9780061120084",
friendlyName = "International Standard Book Number",
}
};
UPDATE
OK, another approach would be to create a custom XmlWriter that can intercept calls made by the serializer to create elements. When an element is being created for an property that you want to add a friendly name to, you can write in your own custom attribute.
public class MyXmlTextWriter : XmlTextWriter
{
public MyXmlTextWriter(TextWriter w)
: base(w)
{
}
public override void WriteStartElement(string prefix, string localName, string ns)
{
base.WriteStartElement(prefix, localName, ns);
switch(localName)
{
case "ISBN":
WriteAttributeString("friendlyName", "International Standard Book Number");
break;
}
}
}
Here is an example of how you would use it (from a console app):
XmlSerializer serializer = new XmlSerializer(typeof(Book));
serializer.Serialize(new MyXmlTextWriter(Console.Out), b);
You can implement the other constructors of XmlTextWriter, if you need to be able to write to other things like a Stream.