简体   繁体   中英

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.

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 ;)

Not sure if this helps, but if I run this code (in Linqpad)

string x = "<commandText> Select ProductID, ProductName&#xD;&#xA;     From   Product</commandText>";
var wrapper = new StringReader(x);
XmlReader xr = XmlReader.Create(wrapper);
xr.MoveToContent();
xr.ReadOuterXml().Dump();

I get this literal output:

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

So if you are using an XmlReader on the server, there should not be any need to manipulate the entities via a transform. The XmlReader should interpret them just fine. Not sure if that was the issue though...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM