我正在开发一个 C# 应用程序,该应用程序将两个 Xml 文档分开,合并它们的一些标记内容,并生成第三个 Xml 文档。我面临一种情况,我需要提取一个标签的值,包括内部标签,并将其转移到另一个标签。我开始做这样的事情:
var summaryElement = elementExternal.Element("summary");
var summaryValue = (string)summaryElement;
var summaryValueClean = ElementValueClean(summaryValue);
var result = new XElement("para", summaryValueClean)
ElementValueClean 函数删除无关空白的地方。
如果摘要标签的值仅包含文本,这将令人满意。当摘要标签包含子元素时,问题就来了:
<summary>
Notifies the context that a new link exists between the <paramref name="source" /> and <paramref name="target" /> objects
and that the link is represented via the source.<paramref name="sourceProperty" /> which is a collection.
The context adds this link to the set of newly created links to be sent to
the data service on the next call to SaveChanges().
</summary>
我想制作这样的东西:
<para>
Notifies the context that a new link exists between the <paramref name="source" /> and <paramref name="target" /> objects
and that the link is represented via the source.<paramref name="sourceProperty" /> which is a collection.
The context adds this link to the set of newly created links to be sent to
the data service on the next call to SaveChanges().
</para>
在我的源标签目录中可能出现大约十几个可能的嵌入标签,我必须将其内容合并到输出标签中。所以我想要一个可以概括的 C# 解决方案。但是,如果它足够简单,我可以将其应用于 Xml 片段以生成 Xml 片段的 Xslt 转换也对我有用。我的 Xslt 技能因废弃而减少。