我有一个像这样的文件xml:
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1">
<g ID="Prova1"/>
<g ID="Prova2"/>
</svg>
我需要在节点中添加一些属性 例如:
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1">
<g ID="Prova1" onclick="prova()" />
<g ID="Prova2" onclick="prova()" />
</svg>
如果id为null,我不做任何事情。 我使用VB.net和类XElement
答案 0 :(得分:1)
试一试
Dim someXE As XElement = <svg version="1.1">
<g ID="Prova1"/>
<g ID="Prova2"/>
</svg>
For Each xe As XElement In someXE.Elements
xe.@onclick = "prova()"
Next
答案 1 :(得分:0)
试试这个
Imports System.Xml
Imports System.Xml.Linq
Module Module1
Sub Main()
Dim xml As String = "<?xml version=""1.0"" encoding=""utf-8""?>" & _
"<svg version=""1.1"">" & _
"<g ID=""Prova1""/>" & _
"<g ID=""Prova2""/>" & _
"</svg>"
Dim element As XElement = XElement.Parse(xml)
For Each g As XElement In element.Descendants("g")
g.Add(New XAttribute("onclick", "prova()"))
Next g
End Sub
End Module