gpt4 book ai didi

c# - 是否可以在 C# 项目中使用 XDT?

转载 作者:行者123 更新时间:2023-12-04 00:06:54 24 4
gpt4 key购买 nike

我在数据库表中有 XML,需要根据特定条件转换更新值、简单更改。

我做了研究,但只找到了适用于 Web.Config 或 App.Config 的工具/插件:

http://ctt.codeplex.com/

http://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5

我可以使用 XSLT,但 XDT 似乎更理想、更简单,但我如何在我的 C# 项目中使用它?

谢谢

最佳答案

对于看到这篇文章的任何人,有一个 NuGet 包提供了执行此转换的能力:

Install-Package Microsoft.Web.Xdt

然后,它是这样的:

// Some example file paths
var sourceDoc = "web.config";
var transDoc = "web.Debug.config";
var destDoc = "bin\web.config";

// The translation at-hand
using (var xmlDoc = new XmlTransformableDocument())
{
xmlDoc.PreserveWhitespace = true;
xmlDoc.Load(sourceDoc);

using (var xmlTrans = new XmlTransformation(transDoc))
{
if (xmlTrans.Apply(xmlDoc))
{
// If we made it here, sourceDoc now has transDoc's changes
// applied. So, we're going to save the final result off to
// destDoc.
xmlDoc.Save(destDoc);
}
}
}

当然,这是非常基本的,只需最少的检查,但它为您提供了要点。

关于c# - 是否可以在 C# 项目中使用 XDT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10229820/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com