Ok gracias, he reducido la cantidad de código en muchas líneas con ésta clase.
Ahora me surge otro problema, después de leer el archivo xml que es de este tipo:
Código PHP:
<FOLDER ID_FOLDER="0" ID_PARENT="-1">
<DESC_FOLDER>The Company</DESC_FOLDER>
<TOOLTIP>Company</TOOLTIP>
</FOLDER>
<FOLDER ID_FOLDER="1" ID_PARENT="0">
<DESC_FOLDER>Central</DESC_FOLDER>
<TOOLTIP>Central of the Company</TOOLTIP>
</FOLDER>
....
guardo en una lista todos los FOLDERS del xml, ahora lo que quiero es mostrar en un treeFolder el contenido de esa lista en orden jerarquico, es decir, Central es hijo de The company ya que su ID_PARENT es igual al ID_FOLDER de The Company, pero no me lo hace bien, me repite campos. Si alguien me puediese revisar el código para ver que falla lo agradecería.
Código PHP:
protected void LoadFolders(string folderList)
{
string parent = string.Empty;
string id = string.Empty, idAux = string.Empty;
string nombre = string.Empty;
string text = string.Empty;
string tooltip = string.Empty;
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(folderList);
XmlNode node; node = xDoc.DocumentElement;
List<Nodo> nodos = new List<Nodo>();
foreach (XmlNode node1 in node.ChildNodes)
{
if (node1.Name == "FOLDER")
{
id = node1.Attributes["ID_FOLDER"].Value;
parent = node1.Attributes["ID_PARENT"].Value;
}
foreach (XmlNode node2 in node1.ChildNodes)
if (node2.Name == "DESC_FOLDER")
{
text = node2.InnerText;
}
else if (node2.Name == "TOOLTIP")
{
tooltip = node2.InnerText;
}
nodos.Add(new Nodo(id, parent, text, tooltip));
}
System.Web.UI.WebControls.TreeNode parentNode = new System.Web.UI.WebControls.TreeNode();
string idPadre = string.Empty;
foreach (Nodo nodo in nodos)
{
List<Nodo> hijos = FindChildrens(nodos, nodo);
if (hijos != null)
{
foreach (Nodo hijo in hijos)
{
System.Web.UI.WebControls.TreeNode childNode = new System.Web.UI.WebControls.TreeNode();
System.Web.UI.WebControls.TreeNode parentNodeAux = new System.Web.UI.WebControls.TreeNode();
parentNodeAux.Text = nodo.Text;
parentNodeAux.ToolTip = nodo.Tooltip;
parentNodeAux.Value = nodo.Id;
childNode.Text = hijo.Text;
childNode.ToolTip = hijo.Tooltip;
childNode.Value = hijo.Id;
if (nodo.Parent.Equals("-1"))
{
parentNode.Text = nodo.Text;
parentNode.Value = nodo.Id;
parentNode.ToolTip = nodo.Tooltip;
parentNode.ChildNodes.Add(childNode);
}
else
{
parentNodeAux.ChildNodes.Add(childNode);
idPadre = buscarPadre(nodo.Parent, nodos);
if (idPadre != null)
if (idPadre == nodo.Parent)
parentNode.ChildNodes.Add(parentNodeAux);
}
}
}
}
treeFolders.Nodes.Add(parentNode);
treeFolders.ExpandAll();
}
Gracias