更新
更旧
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Xml.Linq;
namespace RepoTasks.CodeGen
{
class DirectedGraphXml
{
private readonly XNamespace _ns = "http://schemas.microsoft.com/vs/2009/dgml";
private readonly XDocument _doc;
private readonly XElement _nodes;
private readonly XElement _links;
public DirectedGraphXml()
{
_doc = new XDocument(new XElement(_ns + "DirectedGraph"));
_nodes = new XElement(_ns + "Nodes");
_links = new XElement(_ns + "Links");
_doc.Root.Add(_nodes);
_doc.Root.Add(_links);
}
public void AddNode(string id)
{
_nodes.Add(new XElement(_ns + "Node", new XAttribute("Id", id), new XAttribute("Label", id)));
}
public void AddLink(string source, string target)
{
_links.Add(new XElement(_ns + "Link",
new XAttribute("Source", source),
new XAttribute("Target", target)));
}
public void Save(string path)
{
_doc.Save(path);
}
}
}