Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 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.Xml.Linq;
  7.  
  8. namespace xml
  9. {
  10.     class Program
  11.     {
  12.         static XDocument Betoltes()
  13.         {
  14.             //XDocument.Load("workers.xml"); //local bin/debug
  15.             return XDocument.Load("http://users.nik.uni-obuda.hu/siposm/db/workers.xml");
  16.         }
  17.  
  18.         static void Main(string[] args)
  19.         {
  20.             XDocument allomany = Betoltes();
  21.             var mailok = from x in allomany.Root.Descendants("person")
  22.                          select x.Element("email").Value;
  23.  
  24.             var tamasok = from x in allomany.Root.Descendants("person")
  25.                           where x.Element("name").Value.ToUpper().Contains("TAMÁS")
  26.                           select x.Element("name").Value;
  27.  
  28.             var polihisztorok = from x in allomany.Root.Descendants("person")
  29.                                 where x.Element("rank").Value.Equals("polihisztor")
  30.                                 select new
  31.                                 {
  32.                                     NEV = x.Element("name").Value,
  33.                                     MAIL = x.Element("email").Value
  34.                                 };
  35.             var intezetek = from x in allomany.Root.Descendants("person")
  36.                             group x by x.Element("dept").Value into g
  37.                             select new
  38.                             {
  39.                                 LETSZAM = g.Count(),
  40.                                 INTEZET = g.Key
  41.                             };
  42.             XElement uj = new XElement("person",
  43.                 new XElement("name","ULTRON"),
  44.                 new XElement("email", "U@MAIL.HU"),
  45.                 new XElement("dept", "AII")
  46.                 //----
  47.                 );
  48.             allomany.Root.Add(uj);
  49.                            
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement