Sample XML File
[sourcecode language="xml"]
<?xml version="1.0" encoding="utf-8"?>
<PatientInfo>
<Patient id=”1”>
<app-no>03</app-no>
<fname>Brian</fname>
<lname>Marsh</lname>
<docId>03</docId>
</Patient>
<Patient id=”2”>>
<app-no>02</app-no>
<fname>Bron</fname>
<lname>Marini</lname>
<docId>01</docId>
</Patient>
</PatientInfo>
[/sourcecode]
The Code
[sourcecode language="csharp"]
XmlDocument doc = new XmlDocument();
doc.Load("files/sampleXML.xml");
XmlNodeList patientList = doc.GetElementsByTagName("Patient ");
foreach (XmlNode node in patientList)
{
XmlElement patientElement = (XmlElement) node;
string first_name = patientElement.GetElementsByTagName("fname")[0].InnerText;
string last_name = patientElement.GetElementsByTagName("lname")[0].InnerText;
string patient_id = "";
if (patientElement.HasAttributes)
{
patient_id = patientElement.Attributes["id"].InnerText;
}
Console.WriteLine("{0} ({1}) {2}\n", first_name, last_name, patient_id);
}
[/sourcecode]
Subscribe to:
Post Comments (Atom)
How to enable CORS in Laravel 5
https://www.youtube.com/watch?v=PozYTvmgcVE 1. Add middleware php artisan make:middleware Cors return $next($request) ->header('Acces...
-
< Requirements Java Development Kit (JDK) NetBeans IDE Apache Axis 2 Apache Tomcat Server Main Topics Setup Development Environ...
-
Download Sourcecode [sourcecode language="csharp"] using System; using System.Collections.Generic; using System.Linq; using System...
Very nice article. I really enjoyed it reading. And it also cleared lot of my doubts about reading XML file using C# code. You made it very simple and understandable. I would like to appreciate you that keep writing. There is also an article which explained very well on this topic and I was found it at searching time. Check it at once too...
ReplyDeletehttp://mindstick.com/Articles/851bfc02-9c84-41c4-a3ca-d83b5fd0adf2/?How%20to%20read%20data%20from%20XML%20file%20in%20C%20Sharp
Thank you, Abhinav
ReplyDelete