Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using System.Xml.Linq;
  8. using System.Xml;
  9.  
  10. namespace Xml36
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             XDocument xdoc = XDocument.Load("Wrd.xml");
  17.            
  18.             //IEnumerable<XElement> mas = from elm in xdoc.Root.Descendants() where el.Parent.Name == xdoc.Root.Name select elm;
  19.            
  20.                 IEnumerable<XElement> mas = from ele in xdoc.Root.Descendants()  select ele;
  21.  
  22.             foreach (XElement ele in mas)
  23.             {
  24.                 try
  25.                 {
  26.                     if (ele.Parent.Parent.Name == xdoc.Root.Name)
  27.                     {
  28.                         {
  29.                             int n = 0;
  30.                             Console.WriteLine(ele.ToString());
  31.                             IEnumerable<XElement> mas3 = from elem in ele.Descendants() select elem;
  32.  
  33.  
  34.                             foreach (XElement elem in mas3)
  35.                             {
  36.                                 n++;
  37.                             }
  38.                             XAttribute ndct = new XAttribute("node-count", n);
  39.                             ele.Add(ndct);
  40.                         }
  41.                     }
  42.                 }
  43.                 catch { }
  44.             }
  45.                    
  46.                
  47.            
  48.             xdoc.Save("wrdd.xml");
  49.             Console.ReadLine();
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement