如何将XML名称空间提升到根元素

问题描述 投票:1回答:1

如果我有一个带有如下名称空间的XML文件:

<root>

<h:table xmlns:h="http://www.namespaces.com/namespaceOne">
  <h:tr>
    <h:td>Apples</h:td>
    <h:td>Bananas</h:td>
  </h:tr>
</h:table>

<h:table xmlns:h="https://www.namespaces.com/namespaceTwo">
  <h:name>African Coffee Table</h:name>
  <h:width>80</h:width>
  <h:length>120</h:length>
</h:table>

</root>

我想将所有名称空间提升到根元素,像这样:

<root xmlns:h="http://www.namespaces.com/namespaceOne" xmlns:h1="https://www.namespaces.com/namespaceTwo">

<h:table>
  <h:tr>
    <h:td>Apples</h:td>
    <h:td>Bananas</h:td>
  </h:tr>
</h:table>

<h1:table>
  <h1:name>African Coffee Table</h1:name>
  <h1:width>80</h1:width>
  <h1:length>120</h1:length>
</h1:table>

</root>

有没有办法做到这一点?理想情况下,自动地解决冲突的名称空间前缀,如上例所示。我尚未承诺使用Linq to XMLSystem.Xml,所以有可能。

有一个主要限制:由于我正在工作的环境,我无法编写类。我可以编写函数,但不能编写新的类定义。

c# xml vb.net xml-namespaces workflow-foundation
1个回答
2
投票

结果证明这很简单:

© www.soinside.com 2019 - 2024. All rights reserved.