Saturday 31 May 2014

Convert Object into Xml Format

 public XmlNode CreateXML(Object YourClassObject)
    {
        XmlDocument xmlDoc = new XmlDocument();   //Represents an XML document,
        // Initializes a new instance of the XmlDocument class.         
        XmlSerializer xmlSerializer = new XmlSerializer(YourClassObject.GetType());
        // Creates a stream whose backing store is memory.
        using (MemoryStream xmlStream = new MemoryStream())
        {
            xmlSerializer.Serialize(xmlStream, YourClassObject);
            xmlStream.Position = 0;
            //Loads the XML document from the specified string.
            xmlDoc.Load(xmlStream);
            return xmlDoc;
        }
    }

No comments:

Post a Comment

रूस-यूक्रेन संकट लाइव: भारतीयों को 'उपलब्ध किसी भी साधन' के माध्यम से कीव को तत्काल छोड़ने के लिए कहा

  रूस यूक्रेन संकट लाइव: कीव में भारतीय दूतावास ने मंगलवार को जारी एक एडवाइजरी में भारतीयों को  'किसी भी उपलब्ध साधन' के माध्यम से क...