Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to check if the Node has only empty descendants
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
XML
Titre:
How to check if the Node has only empty descendants
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01567676
Message ID:
01567676
Vues:
42
Hi everybody,

I have the following code:
XDocument doc = XDocument.Parse(input);

         var nodes = doc.Element(rootNode).Descendants()
             .Where(n => (n.Value != "0" && n.Value != ".00" && n.Value != "false" && n.Value != "") || n.HasElements)
             .Select(n => new { n.Name, n.Value, Level = n.Ancestors().Count() - 1, n.HasElements, Descendants = n.Descendants().Count() });

         var output = new StringBuilder();

         foreach (var node in nodes)
         {
            if (node.HasElements)
            {
               output.AppendLine(new string(' ', node.Level) + node.Name.ToString() + ":");
               if (0 == node.Descendants)
                  output.AppendLine("");
            }
            else
            {
             //else code here            }
         }
         return output.ToString().TrimEnd('\r', '\n'); 
      }
My problem is that I want to insert an empty line in case my first element has only 1 empty child node element. I can not figure out how to make a check for this.

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform