Я решил свою проблему:)
XElement elServices = new XElement("services");
foreach (TreeNode serviceNode in treeView1.Nodes)
{
XElement elService = new XElement("service",
new XElement("name", serviceNode.Text));
XElement elCategories = new XElement("categories");
foreach (TreeNode categoryNode in serviceNode.Nodes)
{
XElement elCategory = new XElement("category",
new XElement("name", categoryNode.Text));
XElement elMethods = new XElement("methods");
foreach (TreeNode methodNode in categoryNode.Nodes)
{
XElement elMethod = new XElement("method",
new XElement("name", methodNode.Text));
elMethods.Add(elMethod);
}
elCategory.Add(elMethods);
elCategories.Add(elCategory);
}
elService.Add(elCategories);
elServices.Add(elService);
}
MessageBox.Show(elServices.ToString());