Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Xml;
- using System.Xml.Linq;
- using System.Xml.XPath;
- namespace parseXML
- {
- class Program
- {
- static XmlElement getProjectsNode(XmlDocument xdocument)
- {
- xdocument.Load("D:\\testxml.xml");
- XmlElement responseElement=null;
- XmlElement ProjectElement=null;
- foreach (var p in xdocument.ChildNodes)
- {
- if (p is XmlElement)
- {
- Debug.Print("Element Name");
- XmlElement castme = p as XmlElement;
- Console.WriteLine("Name=" + castme.Name + "\n");
- if (castme.Name.Equals("response", StringComparison.OrdinalIgnoreCase))
- {
- responseElement=castme;
- break;
- }
- }
- }
- if (responseElement != null)
- {
- foreach (var p in responseElement.ChildNodes)
- {
- if (p is XmlElement)
- {
- XmlElement testproj = p as XmlElement;
- Console.WriteLine("child node:" + testproj.Name);
- if(testproj.Name.Equals("projects",StringComparison.OrdinalIgnoreCase))
- {
- return testproj;
- }
- }
- }
- }
- return null;
- }
- static void Main(string[] args)
- {
- XmlDocument xdocument = new XmlDocument();
- xdocument.Load("D:\\TestXML.xml"); //Change this obviously.
- var projectsnode = getProjectsNode(xdocument);
- if (projectsnode != null)
- {
- foreach (var p in projectsnode.ChildNodes)
- {
- if (p is XmlElement)
- {
- XmlElement castit = p as XmlElement;
- Console.WriteLine("name:" + castit.Name);
- var idelem = castit.GetElementsByTagName("id");
- }
- }
- }
- Console.ReadLine();
- }
- }
- }
Add Comment
Please, Sign In to add comment