Load xml data from a string
using System;
using System.Xml;
class MainClass
{
static void Main(string[] args)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml("<Record> write something</Record>");
xmlDoc.Save(Console.Out);
}
}
Load XML data from string and output
using System;
using System.Xml;
class MainClass
{
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<R> Value </R>");
XmlNode root = doc.DocumentElement;
doc.Save(Console.Out);
root.RemoveAll();
doc.Save(Console.Out);
}
}
Post XML to URL as cURL
public string POSTXml(string xml, string url)
{
WebRequest req = null;
WebResponse rsp = null;
try
{
StringBuilder strRequest = new StringBuilder();
req = WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "text/xml";
StreamWriter writer = new StreamWriter(req.GetRequestStream());
writer.WriteLine(xml);
writer.Close();
rsp = req.GetResponse();
var sr = new StreamReader(rsp.GetResponseStream());
string responseText = sr.ReadToEnd();
return responseText;
}
catch (Exception e)
{
throw new Exception("There was a problem sending the message");
}
}