Guest User

Untitled

a guest
Nov 24th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Xml;
  7. using System.Xml.Linq;
  8. using System.Xml.XPath;
  9. namespace parseXML
  10. {
  11.     class Program
  12.     {
  13.         static XmlElement getProjectsNode(XmlDocument xdocument)
  14.         {
  15.              
  16.  
  17.  
  18.  
  19.             xdocument.Load("D:\\testxml.xml");
  20.             XmlElement responseElement=null;
  21.             XmlElement ProjectElement=null;
  22.             foreach (var p in xdocument.ChildNodes)
  23.             {
  24.        
  25.                 if (p is XmlElement)
  26.                 {
  27.                     Debug.Print("Element Name");
  28.                    
  29.                     XmlElement castme = p as XmlElement;
  30.                     Console.WriteLine("Name=" + castme.Name + "\n");
  31.                     if (castme.Name.Equals("response", StringComparison.OrdinalIgnoreCase))
  32.                     {
  33.                         responseElement=castme;
  34.                         break;
  35.  
  36.  
  37.  
  38.                     }
  39.  
  40.  
  41.  
  42.                 }
  43.  
  44.                
  45.                
  46.  
  47.  
  48.             }
  49.             if (responseElement != null)
  50.             {
  51.                 foreach (var p in responseElement.ChildNodes)
  52.                 {
  53.                     if (p is XmlElement)
  54.                     {
  55.                         XmlElement testproj = p as XmlElement;
  56.                         Console.WriteLine("child node:" + testproj.Name);
  57.                         if(testproj.Name.Equals("projects",StringComparison.OrdinalIgnoreCase))
  58.                         {
  59.                        
  60.                            return testproj;
  61.  
  62.                         }
  63.  
  64.                     }
  65.  
  66.  
  67.                 }
  68.  
  69.  
  70.             }
  71.  
  72.             return null;
  73.         }
  74.  
  75.         static void Main(string[] args)
  76.         {
  77.          
  78.              XmlDocument xdocument = new XmlDocument();
  79.              xdocument.Load("D:\\TestXML.xml"); //Change this obviously.
  80.              var projectsnode = getProjectsNode(xdocument);
  81.  
  82.              if (projectsnode != null)
  83.              {
  84.  
  85.                  foreach (var p in projectsnode.ChildNodes)
  86.                  {
  87.  
  88.                      if (p is XmlElement)
  89.                      {
  90.                          XmlElement castit = p as XmlElement;
  91.                          Console.WriteLine("name:" + castit.Name);
  92.                          var idelem = castit.GetElementsByTagName("id");
  93.                          
  94.  
  95.  
  96.                      }
  97.  
  98.  
  99.                  }
  100.  
  101.  
  102.              }
  103.             Console.ReadLine();
  104.  
  105.  
  106.  
  107.         }
  108.     }
  109. }
Add Comment
Please, Sign In to add comment