Donate

Read Or Parse XML Using XmlElement Class, XPath And XmlNodelist In C#

Sample xml file:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
<?xml version="1.0" encoding="UTF-8"?>
<jobs>
   <job>
      <title>Payroll Analyst</title>
      <description>
         <summary>Seeking Payroll Analyst specialists.    
  Great benefits and competitive salary. Must meet all requirements    
  to be considered for assignment.</summary>
      </description>
      <location>
         <state>Pennsylvenia</state>
      </location>
   </job>
   <job />
</jobs>
Code:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
ListingSource = webclient.DownloadString("your_xmlurl");  
StringReader readString = new System.IOStringReader(ListingSource);  
XmlDocument awesome = new XmlDocument();  
awesome.Load(readString);  
XmlNodeList nodeList = awesome.SelectNodes("//jobs/job");  
foreach (XmlElement element in nodeList)  
{  
    title = element["title"].InnerText.Trim();  
    state_name_text = element["location"]["state"].InnerText.Trim();   
    description = element["description"]["summary"].InnerText.Trim();  
} 

Comments

Post a Comment

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.