1

我有一个这样的xml字符串

<root>
Am trying <br id="9"/>to reorder the <br id="5"/>break 
lines <br id="10"/> attributes value
</root>

将XML BR标签ID属性的属性值更改为这样的顺序的任何方法

<root>
Am trying <br id="1"/>to reorder the <br id="2"/>break 
lines <br id="3"/> attributes value
</root>
4

1 回答 1

1

这是一个使用LINQ TO XML的示例

Dim doc as XElement = <root>
Am trying <br id="9"/>to reorder the <br id="5"/>break 
lines <br id="10"/> attributes value
</root>

Dim index as Integer = 0

For Each br In doc.<br>
    index += 1
    br.@id = index
Next 

这导致以下输出

<root>
Am trying <br id="1" />to reorder the <br id="2" />break 
lines <br id="3" /> attributes value
</root>

此外,这是一个使用LAMBDA表达式的示例。

doc.<br>.ToList().ForEach(Sub(br) 
                index += 1 
                br.@id = index 
              End Sub)
于 2012-10-03T03:58:54.277 回答