Avatar of mkarthik415
mkarthik415
 asked on

Retrieve Xml elements using c#

Hi

How to retrieve the "SampleName","1234","07-07-1977" from the below xml document. I tried loading that into xmldocument and loop but realized that is not efficient as the actual document has many elements.

<?xml version="1.0" encoding="utf-8" ?>
<fC xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.test.com">
  - <fF>
    - <f d:name="a1" xmlns:d="http://www.test.com">
      <d:text>Medha</d:text>
      <d:restriction>REQUIRED</d:restriction>
    </f>
    - <f d:name="a2" xmlns:d="http://www.test.com">
      <d:text>11111</d:text>
      <d:restriction>REQUIRED</d:restriction>
    </f>
    - <f d:name="a3" xmlns:d="http://www.test.com">
      <d:date>07-07-1999</d:date>
      <d:restriction>REQUIRED</d:restriction>
    </f>    
  </fF>
</fC>

Please suggest any resources or sample code.
Thank You
XMLC#.NET Programming

Avatar of undefined
Last Comment
Navneet Hegde

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Navneet Hegde

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Navneet Hegde

XmlNodeList xnList = xml.SelectNodes("/fC/fF/f");
foreach (XmlNode xn in xnList)
{
  string myText = xn["d:text"].InnerText;
  Console.WriteLine("My Text: {0}", myText);
}



Can you try this!


Thanks!
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes