你好:)
参考代码如下:
namespace ConsoleApplicationZhiShu
{
public class Eratosthenes
{
static void AddElement(int times,XElement ele)
{
if (times > 10) //总共添加10个节点
{
return;
}
else
{
XElement e = new XElement("Member" + times);
ele.Add(e);
AddElement(times + 1,e);
}
}
static void Main(string[] args)
{
XDocument doc = XDocument.Load("XMLFile3.xml");
AddElement(1,doc.Root);
doc.Save("C:\\try.xml");
Console.WriteLine("OK");
}
}
}
【vb代码】
Namespace ConsoleApplicationZhiShu
Public Class Eratosthenes
Private Shared Sub AddElement(times As Integer, ele As XElement)
If times > 10 Then
'总共添加10个节点
Return
Else
Dim e As New XElement("Member" & times)
ele.Add(e)
AddElement(times + 1, e)
End If
End Sub
Private Shared Sub Main(args As String())
Dim doc As XDocument = XDocument.Load("XMLFile3.xml")
AddElement(1, doc.Root)
doc.Save("C:\try.xml")
Console.WriteLine("OK")
End Sub
End Class
End Namespace
如果你有其它意见或私下交流,请发送邮件到:maledong@qq.com;或者请
下载MSDN桌面工具(Vista,Win7)
下载Technet桌面小工具(Vista,Win7)
慈善点击,点击此处