none
XML In Code Behind RRS feed

  • Question

  • Hi all,

    In VB.NET, inside a code behind file I can create a string variable and assign XML data to it. The XML is automatically formatted in XML format.

    Dim test As String = <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    
                                     </soapenv:Envelope>

    However, when I try to do the same in C#, it does not happen. The XML is considered to have errors.

    Any ideas how I can accomplish this?

    Thanks in advance.

     
    Friday, March 15, 2013 5:16 PM

Answers

  • Try something like:

    XDocument doc = XDocument.Parse(str);

    where variable str is your xml string.

    wizend

    • Marked as answer by admdev Monday, March 25, 2013 11:21 AM
    Friday, March 15, 2013 5:23 PM
  • AdmDev is the string content static ?  Does this help 

         string test = @"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/""></soapenv:Envelope>";
               XDocument objDoc = XDocument.Parse(test);
               Console.WriteLine(objDoc);

    • Marked as answer by admdev Monday, March 25, 2013 11:21 AM
    Friday, March 15, 2013 5:24 PM

All replies

  • Try something like:

    XDocument doc = XDocument.Parse(str);

    where variable str is your xml string.

    wizend

    • Marked as answer by admdev Monday, March 25, 2013 11:21 AM
    Friday, March 15, 2013 5:23 PM
  • AdmDev is the string content static ?  Does this help 

         string test = @"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/""></soapenv:Envelope>";
               XDocument objDoc = XDocument.Parse(test);
               Console.WriteLine(objDoc);

    • Marked as answer by admdev Monday, March 25, 2013 11:21 AM
    Friday, March 15, 2013 5:24 PM
  • Thanks guys.

    I will try your suggestions.

    Friday, March 15, 2013 6:44 PM