Xml 用于查找和替换的文档转换 价值观
Xml Document Transform to find and replace 
 values
我有一个 xml 文档,其中有一个 sql 查询。假设它看起来像这样:
<commandText> Select ProductID, ProductName
From Product</commandText>
当它通过 octopack 运行 并部署(通过章鱼部署)到我的服务器时,它看起来像这样:
<commandText> Select ProductID, ProductName
 From Product</commandText>
(换行符被转换为

)
是否有 xml 转换我可以 运行 在进行此更改后将其转换回来? (或至少删除 

)
注意:我的实际查询是一个复杂的合并语句,因此我宁愿不要将它放在多个地方。
您要查找的是此处描述的 XmlDocument 的 WHITESPACE PRESERVE 函数 https://msdn.microsoft.com/en-us/library/system.xml.xmldocument.preservewhitespace%28v=vs.110%29.aspx
第二种(也是最好的)方法是让 XML 自动解码。您使用错误的方法来读出 select 语句 ;)
不确定这是否有帮助,但如果我 运行 此代码(在 Linqpad 中)
string x = "<commandText> Select ProductID, ProductName
 From Product</commandText>";
var wrapper = new StringReader(x);
XmlReader xr = XmlReader.Create(wrapper);
xr.MoveToContent();
xr.ReadOuterXml().Dump();
我得到这个文字输出:
<commandText> Select ProductID, ProductName
From Product</commandText>
因此,如果您在服务器上使用 XmlReader,则无需通过转换来操作实体。 XmlReader 应该很好地解释它们。不确定这是否是问题所在...
我有一个 xml 文档,其中有一个 sql 查询。假设它看起来像这样:
<commandText> Select ProductID, ProductName
From Product</commandText>
当它通过 octopack 运行 并部署(通过章鱼部署)到我的服务器时,它看起来像这样:
<commandText> Select ProductID, ProductName
 From Product</commandText>
(换行符被转换为

)
是否有 xml 转换我可以 运行 在进行此更改后将其转换回来? (或至少删除 

)
注意:我的实际查询是一个复杂的合并语句,因此我宁愿不要将它放在多个地方。
您要查找的是此处描述的 XmlDocument 的 WHITESPACE PRESERVE 函数 https://msdn.microsoft.com/en-us/library/system.xml.xmldocument.preservewhitespace%28v=vs.110%29.aspx
第二种(也是最好的)方法是让 XML 自动解码。您使用错误的方法来读出 select 语句 ;)
不确定这是否有帮助,但如果我 运行 此代码(在 Linqpad 中)
string x = "<commandText> Select ProductID, ProductName
 From Product</commandText>";
var wrapper = new StringReader(x);
XmlReader xr = XmlReader.Create(wrapper);
xr.MoveToContent();
xr.ReadOuterXml().Dump();
我得到这个文字输出:
<commandText> Select ProductID, ProductName
From Product</commandText>
因此,如果您在服务器上使用 XmlReader,则无需通过转换来操作实体。 XmlReader 应该很好地解释它们。不确定这是否是问题所在...