How to keep Xml from killing NewLines in Strings? RRS feed

  • Question

  • User-359936451 posted

    I have some standard web services used to pass in and out data from a sql express database on a web site. The VB.net app which runs on a client PC makes comparisons against some of the text string data returned from these web services.

    Some of the text strings have CRLF embedded in the text string to create multi-paragraph type text blocks for presentation to the users.

    This data is also stored in an Access database on the local PC.

    I have discovered that the CRs are being removed from the text string as is the standard of XML.


    How can I put them back in or get XML to leave them in? Isn't there a Normilzation setting that will over ride this behavior?

    All of my web services were created by the Visual Studio wizards to build the WSDL, not sure I can change that code without breaking it.




    Monday, June 3, 2013 2:41 PM


All replies

  • User-837620913 posted

    Wrap the contents in a CDATA section, like this:

        Hey look I can use reserved characters
        like > < " and &
        or xml tags like <joe>NeedsCoffee</joe>
        Also the line breaks are here

    You can use CData tags in .NET easily like this:

    XDocument doc = XDocument.Parse( myXml, LoadOptions.SetLineInfo );
    XElement dataNode = doc.Descendants( "Data" ).First();
    dataNode.Add ( new XCData( "<h1>Hello</h1>" ));

    See more here:


    http://msdn.microsoft.com/en-us/library/bb384869.aspx/html (for VB)


    Tuesday, June 4, 2013 5:56 AM
  • User-359936451 posted

    Thanks for the reply but I am not using any html here, this is a dataadapter that has read records from an Access table and is trying to match against strings returned from a web service which populated a datatable.

    When the strings from the Access table are first read and processed to the web, the CRs are stripped out. This interface is all done in code on a local PC app. The LF which is what is left when the CRs are stripped out allows the strings to display correctly on the web site.

    The issue is that when the local PC app is run again, it thinks that the web site does not have the string since the CRs are missing and so do not match. Long story why I cannot use a key ID.

    not sure how your answer applies.




    Tuesday, June 4, 2013 9:36 AM
  • User1071469379 posted


    You can encode the strings after you read from Access table and decode when insert to datatable. For comparison, you can encode both strings then compare.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 10, 2013 5:25 AM