Posted By

jasonseney on 03/09/09


Tagged

xml c xmldocument


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

ddevening
umang_nine
khouser
Beppoi


Create basic XmlDocument from Scratch


 / Published in: C#
 

Example uses an object from 3rd party API. Needed to turn it into xml for returning from a webservice.

  1. private XmlDocument getXmlResults(CM.Result<int> resultsFromApi) {
  2. XmlDocument returnXmlDoc = new XmlDocument();
  3.  
  4. XmlElement root = returnXmlDoc.CreateElement("result");
  5.  
  6. XmlNode code = returnXmlDoc.CreateNode(XmlNodeType.Element, "code", null);
  7. code.InnerText = resultsFromApi.Code.ToString();
  8.  
  9. XmlNode message = returnXmlDoc.CreateNode(XmlNodeType.Element, "message", null);
  10. message.InnerText = resultsFromApi.Message;
  11.  
  12. root.AppendChild(code);
  13. root.AppendChild(message);
  14. returnXmlDoc.AppendChild(root);
  15.  
  16. return returnXmlDoc;
  17. }

Report this snippet  

You need to login to post a comment.