views:

17

answers:

2

I have a class Image implementing ISerializable:

[Serializable]
[XmlRoot(ElementName = "IMAGE")]
[TypeConverter(typeof(ImageTypeConverter))]
public class ImageResource : ISerializable {
    [XmlAttribute(AttributeName = "TYPE")]
    public string Extension{
        get;
        set;
    }
}

I just want to know if we can get the xml node for an object of this class? Suppose this object is serializes as

<IMAGE TYPE=".mpg"/>

I want to get this Node content as string.

A: 

The XML representation does not exist until you serialize the instance. Once you serialize it, you can manipulate it as XML.

Hint: you should be able to serialize directly into an XDocument:

XDocument doc = new XDocument();
using (XmlWriter writer = doc.CreateNavigator().AppendChild())
{
    XmlSerializer ser = new XmlSerializer(typeof(ImageResource));
    ser.Serialize(instance);
}
John Saunders
A: 

Never mind got the answer from below link text

Ravisha