Example #1
0
        public static void DeserializeFromGraphML <TVertex, TEdge, TGraph>(
#if !NET20
            this
#endif
            TGraph graph,
            XmlReader reader,
            IdentifiableVertexFactory <TVertex> vertexFactory,
            IdentifiableEdgeFactory <TVertex, TEdge> edgeFactory
            )
            where TEdge : IEdge <TVertex>
            where TGraph : IMutableVertexAndEdgeListGraph <TVertex, TEdge>
        {
            Contract.Requires(graph != null);
            Contract.Requires(reader != null);
            Contract.Requires(vertexFactory != null);
            Contract.Requires(edgeFactory != null);

            var serializer = new GraphMLDeserializer <TVertex, TEdge, TGraph>();

            serializer.Deserialize(reader, graph, vertexFactory, edgeFactory);
        }
Example #2
0
        public static void DeserializeAndValidateFromGraphML <TVertex, TEdge, TGraph>(
#if !NET20
            this
#endif
            TGraph graph,
            TextReader reader,
            IdentifiableVertexFactory <TVertex> vertexFactory,
            IdentifiableEdgeFactory <TVertex, TEdge> edgeFactory
            )
            where TEdge : IEdge <TVertex>
            where TGraph : IMutableVertexAndEdgeListGraph <TVertex, TEdge>
        {
            Contract.Requires(graph != null);
            Contract.Requires(reader != null);
            Contract.Requires(vertexFactory != null);
            Contract.Requires(edgeFactory != null);

            var serializer = new GraphMLDeserializer <TVertex, TEdge, TGraph>();
            var settings   = new XmlReaderSettings();

            // add graphxml schema
            settings.ValidationType = ValidationType.Schema;
            settings.XmlResolver    = new GraphMLXmlResolver();
            AddGraphMLSchema <TVertex, TEdge, TGraph>(settings);

            try
            {
                settings.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(ValidationEventHandler);

                // reader and validating
                using (var xreader = XmlReader.Create(reader, settings))
                    serializer.Deserialize(xreader, graph, vertexFactory, edgeFactory);
            }
            finally
            {
                settings.ValidationEventHandler -= new System.Xml.Schema.ValidationEventHandler(ValidationEventHandler);
            }
        }