Create basic XmlDocument from Scratch


/ Published in: C#
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.