this image show what the project does
I can save the canvas to xml like this:
private void SaveFile(object sender, RoutedEventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog()
{
DefaultExt = "xml",
Filter = "XML Files (*.xml)|*.xml|All files (*.*)|*.*",
FilterIndex = 1
};
if (saveFileDialog.ShowDialog() == true)
{
using (Stream stream = saveFileDialog.OpenFile())
{
using (StreamWriter sw = new StreamWriter(stream, System.Text.Encoding.UTF8))
{
sw.Write(GetGeneratedXML().ToString());
}
}
}
}
private XElement GetGeneratedXML()
{
XElement userInformation = new XElement("Diagrama");
foreach (MyBox b in boxes)
{
userInformation.Add(new XElement("Entidade",
new XElement("Nome", b.Header),
new XElement("Atributo", b.Text)));
}
foreach (Connection1 c in connections)
{
userInformation.Add(new XElement("Relação",
new XElement("Entidade1",
new XAttribute("Nome", c.Box1.Header),
new XAttribute("Cardinalidade", c.Node1.Title)),
new XElement("Entidade2",
new XAttribute("Nome", c.Box2.Header),
new XAttribute("Cardinalidade", c.Node2.Title)
)
)
);
}
return userInformation;
}
And now, I would like to import this XML file and then update the Canvas with the boxes and connections. Any Ideas?
Here is a complete roundtrip that illustrates the process:
Hope this helps...
EDIT: here is way to obtain the XML document from a file (to customize a little):
The user selects the file and it is loaded.