Exemplo n.º 1
0
        /// <summary>
        /// This method returns a list with all edges in the file
        /// </summary>
        /// <param name="doc">Representant of the XML file to be read</param>
        /// <param name="points">a list with the nodes</param>
        /// <returns>the edge list</returns>
        private static IEnumerable<AGraphMLEdge> getEdgesFromFile(XmlDocument doc, IEnumerable<AGraphMLNode> points)
        {
            // return value
            List<AGraphMLEdge> edges = new List<AGraphMLEdge>();

            // temporary attributes
            AGraphMLNode pStart;
            AGraphMLNode pEnd;
            string connectionType;

            // set root element
            XmlElement root = doc.DocumentElement;
            // add the namespace
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
            nsmgr.AddNamespace("x", "http://graphml.graphdrawing.org/xmlns");


            // get all xml-tags with nodes
            XmlNodeList nodeList = root.SelectNodes(attributeXPathEdge, nsmgr);

            foreach (XmlNode node in nodeList)
            {
                // init values
                pStart = null;
                pEnd = null;
                connectionType = "";

                // get source / target as attribute from the child
                foreach (XmlAttribute attr in node.Attributes)
                {
                    // get source
                    if (attr.Name == attributeNameSource)
                        pStart = getNodeById(attr.InnerText, points);

                    // get target
                    if (attr.Name == attributeNameTarget)
                        pEnd = getNodeById(attr.InnerText, points);

                }

                // get connection type
                foreach (XmlNode child in node.ChildNodes)
                {
                    // search in attributes
                    foreach (XmlAttribute attr in child.Attributes)
                    {
                        // connection type
                        if (attr.InnerText.Equals(attributeNameConnectionType))
                            connectionType = child.InnerText;
                    }
                }

                // add edge to list
                AGraphMLEdge e = new AGraphMLEdge(pStart, pEnd, connectionType);
                edges.Add(e);
            }

            // return edge list
            return edges;
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method returns a list with all edges in the file
        /// </summary>
        /// <param name="doc">Representant of the XML file to be read</param>
        /// <param name="points">a list with the nodes</param>
        /// <returns>the edge list</returns>
        private static IEnumerable <AGraphMLEdge> getEdgesFromFile(XmlDocument doc, IEnumerable <AGraphMLNode> points)
        {
            // return value
            List <AGraphMLEdge> edges = new List <AGraphMLEdge>();

            // temporary attributes
            AGraphMLNode pStart;
            AGraphMLNode pEnd;
            string       connectionType;

            // set root element
            XmlElement root = doc.DocumentElement;
            // add the namespace
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);

            nsmgr.AddNamespace("x", "http://graphml.graphdrawing.org/xmlns");


            // get all xml-tags with nodes
            XmlNodeList nodeList = root.SelectNodes(attributeXPathEdge, nsmgr);

            foreach (XmlNode node in nodeList)
            {
                // init values
                pStart         = null;
                pEnd           = null;
                connectionType = "";

                // get source / target as attribute from the child
                foreach (XmlAttribute attr in node.Attributes)
                {
                    // get source
                    if (attr.Name == attributeNameSource)
                    {
                        pStart = getNodeById(attr.InnerText, points);
                    }

                    // get target
                    if (attr.Name == attributeNameTarget)
                    {
                        pEnd = getNodeById(attr.InnerText, points);
                    }
                }

                // get connection type
                foreach (XmlNode child in node.ChildNodes)
                {
                    // search in attributes
                    foreach (XmlAttribute attr in child.Attributes)
                    {
                        // connection type
                        if (attr.InnerText.Equals(attributeNameConnectionType))
                        {
                            connectionType = child.InnerText;
                        }
                    }
                }

                // add edge to list
                AGraphMLEdge e = new AGraphMLEdge(pStart, pEnd, connectionType);
                edges.Add(e);
            }

            // return edge list
            return(edges);
        }