public void DeserializeFromGraphML() { foreach (string graphMLFilePath in TestGraphFactory.GetGraphMLFilePaths()) { var graph = new AdjacencyGraph <string, Edge <string> >(); using (var reader = new StreamReader(graphMLFilePath)) { graph.DeserializeFromGraphML( reader, id => id, (source, target, id) => new Edge <string>(source, target)); } var vertices = new Dictionary <string, string>(); foreach (string vertex in graph.Vertices) { vertices.Add(vertex, vertex); } // Check all nodes are loaded #if SUPPORTS_XML_DTD_PROCESSING var settings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, XmlResolver = new GraphMLXmlResolver(), ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings }; using (XmlReader reader = XmlReader.Create(graphMLFilePath, settings)) { #else using (var reader = new XmlTextReader(graphMLFilePath)) { reader.ProhibitDtd = false; reader.XmlResolver = null; #endif var document = new XPathDocument(reader); foreach (XPathNavigator node in document.CreateNavigator().Select("/graphml/graph/node")) { string id = node.GetAttribute("id", ""); Assert.IsTrue(vertices.ContainsKey(id)); } // Check all edges are loaded foreach (XPathNavigator node in document.CreateNavigator().Select("/graphml/graph/edge")) { string source = node.GetAttribute("source", ""); string target = node.GetAttribute("target", ""); Assert.IsTrue(graph.ContainsEdge(vertices[source], vertices[target])); } } } }