Custom Search

Saturday, July 24, 2010

Converting XML to String

In this short post I will show you how to convert XML to String, o viceversa, in order for example, to send it via Tcp/Ip.

In this example, a Client is going to genereta a XML Document and convert it to string.

The Server side must recive the string and generate the XML.

(Here you will not see how the communication is done, for example the convertion between string and stream)

Client Code:

XmlDocument xmlDoc = new XmlDocument();

xmlDoc.Load(@"C:\XML\" + test + ".xml");

//Getting the Xml as String

String message = xmlDoc.InnerXml;


Server Code:

String innerXml = response;

XmlDocument xmlServer = new XmlDocument();

//Set the string to the Xml created above

xmlServer.InnerXml = innerXml;

No comments: