예제 #1
0
 /// <summary>
 /// Si el nodo no existe lo agrego a la lista de nodos
 /// </summary>
 /// <param name="n">Nodo a agregar</param>
 /// <returns>True si el nodo se agrego</returns>
 public bool AgregarNodo(Nodo n)
 {
     if (ExisteNodo(n))
     {
         return(false);
     }
     Nodos.Add(n);
     return(true);
 }
예제 #2
0
        private void generarGrafo()
        {
            while (xml.Read())
            {
                switch (xml.NodeType)
                {
                case XmlNodeType.Element:
                    if (xml.Name == "nodo")
                    {
                        if (xml.HasAttributes)
                        {
                            atributos = new Dictionary <string, string>();
                            string label = "";
                            string id    = "";
                            while (xml.MoveToNextAttribute())
                            {
                                if (xml.Name == "label")
                                {
                                    label = xml.Value;
                                }
                                else if (xml.Name == "id")
                                {
                                    id = xml.Value;
                                }
                            }
                            nodo = new Nodo(id, atributos, label);
                        }
                    }
                    else if (xml.Name == "edge")
                    {
                        if (xml.HasAttributes)
                        {
                            atributos = new Dictionary <string, string>();
                            string label   = "";
                            string origen  = "";
                            string destino = "";
                            while (xml.MoveToNextAttribute())
                            {
                                if (xml.Name == "label")
                                {
                                    label = xml.Value;
                                }
                                else if (xml.Name == "origen")
                                {
                                    origen = xml.Value;
                                }
                                else if (xml.Name == "destino")
                                {
                                    destino = xml.Value;
                                }
                            }
                            edge = new Edge(origen, destino, atributos, label);
                        }
                    }
                    else
                    {
                        key = xml.Name;
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (xml.Name == "nodo" && nodo != null)
                    {
                        Nodos.Add(nodo);
                        nodo = null;
                    }
                    else if (xml.Name == "edge" && edge != null)
                    {
                        Edges.Add(edge);
                        edge = null;
                    }
                    break;

                case XmlNodeType.Text:
                    if (nodo != null)
                    {
                        nodo.Atributos.Add(key, xml.Value);
                    }
                    else if (edge != null)
                    {
                        edge.Atributos.Add(key, xml.Value);
                    }
                    break;
                }
            }
        }
예제 #3
0
        private void generarGrafo()
        {
            while (xml.Read())
            {
                switch (xml.NodeType)
                {
                case XmlNodeType.Element:
                    if (xml.Name == "node")
                    {
                        if (xml.HasAttributes)
                        {
                            atributos = new Dictionary <string, string>();
                            string label = "";
                            string id    = "";
                            while (xml.MoveToNextAttribute())
                            {
                                if (xml.Name == "labels")
                                {
                                    label = xml.Value;
                                }
                                else if (xml.Name == "id")
                                {
                                    id = xml.Value;
                                }
                            }
                            nodo = new Nodo(id, atributos, label);
                        }
                    }
                    else if (xml.Name == "data")
                    {
                        if (xml.HasAttributes)
                        {
                            while (xml.MoveToNextAttribute())
                            {
                                key = xml.Value;
                            }
                        }
                    }
                    else if (xml.Name == "edge")
                    {
                        if (xml.HasAttributes)
                        {
                            atributos = new Dictionary <string, string>();
                            string label   = "";
                            string origen  = "";
                            string destino = "";
                            while (xml.MoveToNextAttribute())
                            {
                                if (xml.Name == "label")
                                {
                                    label = xml.Value;
                                }
                                else if (xml.Name == "source")
                                {
                                    origen = xml.Value;
                                }
                                else if (xml.Name == "target")
                                {
                                    destino = xml.Value;
                                }
                            }
                            edge = new Edge(origen, destino, atributos, label);
                        }
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (xml.Name == "node" && nodo != null)
                    {
                        Nodos.Add(nodo);
                        nodo = null;
                    }
                    else if (xml.Name == "edge" && edge != null)
                    {
                        Edges.Add(edge);
                        edge = null;
                    }
                    break;

                case XmlNodeType.Text:
                    if (nodo != null)
                    {
                        nodo.Atributos.Add(key, xml.Value);
                    }
                    else if (edge != null)
                    {
                        edge.Atributos.Add(key, xml.Value);
                    }
                    break;

                case XmlNodeType.XmlDeclaration:
                    Console.WriteLine("XmlDeclaration.Name: {0}", xml.Name);
                    Console.WriteLine("XmlDeclaration.Value: {0}", xml.Value);
                    break;

                case XmlNodeType.ProcessingInstruction:
                    Console.WriteLine("ProcessingInstruction.Name: {0}", xml.Name);
                    Console.WriteLine("ProcessingInstruction.Value: {0}", xml.Value);
                    break;

                case XmlNodeType.Comment:
                    Console.WriteLine("Comment.Value: {0}", xml.Value);
                    break;
                }
            }
        }
예제 #4
0
 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
 // Métodos
 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
 public void AgregarNodo(Nodo nuevo)
 {
     Nodos.Add(nuevo);
 }