locked
How to convert xml file into a String object in WebService RRS feed

  • Question

  • How to convert xml file into a String object in WebService
    Friday, March 19, 2010 1:37 AM

Answers

  • Hi,

    Try this:

    static string GetXmlString(string strFile)

    {

    // Load the xml file into XmlDocument object.

    XmlDocument xmlDoc = new XmlDocument();

    try

    {

    xmlDoc.Load(strFile);

    }

    catch (XmlException e)

    {

     

    }

    // Now create StringWriter object to get data from xml document.

    StringWriter sw = new StringWriter();XmlTextWriter xw = new XmlTextWriter(sw);

    xmlDoc.WriteTo(xw);

    return sw.ToString();

    }

    HTH Smile

    Friday, March 19, 2010 1:51 AM

All replies

  • Hi,

    Try this:

    static string GetXmlString(string strFile)

    {

    // Load the xml file into XmlDocument object.

    XmlDocument xmlDoc = new XmlDocument();

    try

    {

    xmlDoc.Load(strFile);

    }

    catch (XmlException e)

    {

     

    }

    // Now create StringWriter object to get data from xml document.

    StringWriter sw = new StringWriter();XmlTextWriter xw = new XmlTextWriter(sw);

    xmlDoc.WriteTo(xw);

    return sw.ToString();

    }

    HTH Smile

    Friday, March 19, 2010 1:51 AM
  •  You can also do that:

        XDocument xDoc = XDocument.Load("yourFile.xml");
        string xmlString = xDoc.ToString();
      
    Friday, March 19, 2010 1:58 AM