Add a namespace to the serialization process?

Topics: serialization
May 22, 2012 at 10:37 PM

Hi,

In serializing to GraphML, I would like to serialize my node data into an element structure that is understood by yEd.

As such, I need to add a namespace (xmlns:y="http://www.yworks.com/xml/graphml") to the serializer and customize my node serialization.

    [Serializable]
    public class Node {
        [XmlNamespaceDeclarations]
        public XmlSerializerNamespaces xmlns;

        public Node(string name) {
            Name = name;
            xmlns = new XmlSerializerNamespaces();
            xmlns.Add("y", "http://www.yworks.com/xml/graphml");
            xmlns.Add("yed", "http://www.yworks.com/xml/yed/3");
        }

        [XmlAttribute("Name")]
        public string Name { get; set; }

    }

However, after calling the QuickGraph serializer, 

var settings = new XmlWriterSettings();
settings.Indent = true;

var writer = XmlWriter.Create(outpath + Path.DirectorySeparatorChar + name + ".graphml", settings);
graph.SerializeToGraphML(writer, graph.GetVertexIdentity(), graph.GetEdgeIdentity());
writer.Close();

the new namespaces do not show up.  Anyone encounter such an issue before or know how to solve it?

Thanks,

E.