Search code examples
.netxmlnewlinexdt-transformxdt

Xml Document Transform to find and replace 
 values


I have an xml document that has a sql query in it. Lets say it looks like this for example:

<commandText> Select ProductID, ProductName
              From   Product</commandText>

When this gets run through octopack and deployed (via octopus deploy) onto my server it looks like this:

<commandText> Select ProductID, ProductName&#xD;&#xA;     From   Product</commandText>

(The newline was converted to &#xD;&#xA;)

Is there an xml transform I can run after this change has been made to convert this back? (or at least remove the &#xD;&#xA;)

NOTE: My actual query is a complex merge statement, so I would rather not have it in more than one place.


Solution

  • What you are looking for is WHITESPACE PRESERVE function of XmlDocument described here https://msdn.microsoft.com/en-us/library/system.xml.xmldocument.preservewhitespace%28v=vs.110%29.aspx

    Second (and best) approach is to let XML decode automatically. You are using the wrong method to read out the select statement ;)