Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
How to get values from multiple xml nodes
Abraham Olatubosun
Nov 28 2016 10:33 AM
261
Reply
Hi my Code masters,
I need your help again please, i have this XML file below
<
LaboratoryReport
>
<
VisitID
>
103079
VisitID
>
<
VisitDate
>
2015-06-23
VisitDate
>
<
ARTStatusCode
>
A
ARTStatusCode
>
<
LaboratoryOrderAndResult
>
<
OrderedTestDate
>
2015-06-23
OrderedTestDate
>
<
LaboratoryResultedTest
>
<
Code
>
11
Code
>
<
CodeDescTxt
>
CD4
CodeDescTxt
>
LaboratoryResultedTest
>
<
LaboratoryResult
>
<
AnswerNumeric
>
<
Value1
>
420
Value1
>
AnswerNumeric
>
LaboratoryResult
>
<
ResultedTestDate
>
2015-07-08
ResultedTestDate
>
LaboratoryOrderAndResult
>
<
LaboratoryOrderAndResult
>
<
OrderedTestDate
>
2015-06-23
OrderedTestDate
>
<
LaboratoryResultedTest
>
<
Code
>
46
Code
>
<
CodeDescTxt
>
HIV Rapid Test
CodeDescTxt
>
LaboratoryResultedTest
>
<
LaboratoryResult
>
<
AnswerNumeric
>
<
Value1
>
1
Value1
>
AnswerNumeric
>
LaboratoryResult
>
<
ResultedTestDate
>
2015-07-08
ResultedTestDate
>
LaboratoryOrderAndResult
>
LaboratoryReport
>
<
LaboratoryReport
>
<
VisitID
>
107337
VisitID
>
<
VisitDate
>
2016-05-24
VisitDate
>
<
ARTStatusCode
>
A
ARTStatusCode
>
<
LaboratoryOrderAndResult
>
<
OrderedTestDate
>
2016-05-24
OrderedTestDate
>
<
LaboratoryResultedTest
>
<
Code
>
80
Code
>
<
CodeDescTxt
>
Viral Load
CodeDescTxt
>
LaboratoryResultedTest
>
<
LaboratoryResult
>
<
AnswerNumeric
>
<
Value1
>
18732
Value1
>
AnswerNumeric
>
LaboratoryResult
>
<
ResultedTestDate
>
2016-07-23
ResultedTestDate
>
LaboratoryOrderAndResult
>
LaboratoryReport
>
i want to check if any of the element contain
LaboratoryReport and LaboratoryResultedTest
it should count the element that have it value equal to
CD4
.
this should also happend for any element that have it value equal to
Viral Load
the code is working well for
CD4
but it is not counting for
Viral Load
since the
CD4
is the first element group.
my code is shown bellow :
string
directoryPath = Server.MapPath(
string
.Format(
"~/{0}/"
,
"XML"
));
string
[] filePaths = Directory.GetFiles(directoryPath,
"*.xml"
);
//, SearchOption.AllDirectories
string
fileContent =
""
;
/*=========================================
* this section is to initialise the Excel header and
* the workbook in turn the worksheet
* */
ExcelPackage ps =
new
ExcelPackage();
ps.Workbook.Worksheets.Add(
"EMR-NDR"
);
ExcelWorksheet ws = ps.Workbook.Worksheets[1];
object
missValue = System.Reflection.Missing.Value;
ps.Workbook.Properties.Author =
"Abraham Oaltubosun"
;
ps.Workbook.Properties.Title =
"EMR-NDR Data Extraction Analytics"
;
ExcelRange ChartRange = ws.Cells[
"A1:D1"
];
ws.Cells[1, 1].Value =
"Fil Names"
;
ws.Cells[1, 2].Value =
"HIV Encounter"
;
ws.Cells[1, 3].Value =
"CD4"
;
ws.Cells[1, 4].Value =
"Viral Load"
;
ws.Cells[1, 5].Value =
"ART Regimen"
;
int
t = 2;
foreach
(
string
file
in
filePaths)
{
// Log Message read started
fileContent = File.ReadAllText(file).Trim();
if
(fileContent.Length > 0)
{
XDocument xd = XDocument.Parse(fileContent);
XmlDocument xxd =
new
XmlDocument();
xxd.Load(file);
int
RegimenCounter = 0;
int
RegimenCounter1 = 0;
int
LaboratoryCounter=0;
int
ViralLoadCounter = 0;
string
result =
""
;
HIVEnCounter = xxd.SelectNodes(
"/Container/IndividualReport/Condition/Encounters/HIVEncounter"
).Count;
string
result2 = xd.Element(
"Container"
).Element(
"IndividualReport"
).Element(
"Condition"
).ToString();
if
(result2.Contains(
"Regimen"
))
{
result = xd.Element(
"Container"
).Element(
"IndividualReport"
).Element(
"Condition"
).Element(
"Regimen"
).Element(
"PrescribedRegimenTypeCode"
).Value;
}
if
(!
string
.IsNullOrEmpty(result))
{
if
(result ==
"ART"
)
{
RegimenCounter1 = xxd.SelectNodes(
"/Container/IndividualReport/Condition/Regimen/PrescribedRegimenTypeCode[. = \"ART\"]"
).Count;
}
}
string
result3 = xd.Element(
"Container"
).Element(
"IndividualReport"
).Element(
"Condition"
).ToString();
if
(result3.Contains(
"LaboratoryReport"
) && result3.Contains(
"LaboratoryResultedTest"
))
{
result = xd.Element(
"Container"
).Element(
"IndividualReport"
).Element(
"Condition"
).Element(
"LaboratoryReport"
).Element(
"LaboratoryOrderAndResult"
).Element(
"LaboratoryResultedTest"
).Element(
"CodeDescTxt"
).Value;
}
if
(!
string
.IsNullOrEmpty(result))
{
if
(result ==
"CD4"
)
{
LaboratoryCounter = xxd.SelectNodes(
"/Container/IndividualReport/Condition/LaboratoryReport/LaboratoryOrderAndResult/LaboratoryResultedTest/CodeDescTxt[. =\"CD4\"]"
).Count;
}
}
string
resultVL = xd.Element(
"Container"
).Element(
"IndividualReport"
).Element(
"Condition"
).ToString();
if
(resultVL.Contains(
"LaboratoryReport"
) && resultVL.Contains(
"LaboratoryResultedTest"
))
{
resultVL = xd.Element(
"Container"
).Element(
"IndividualReport"
).Element(
"Condition"
).Element(
"LaboratoryReport"
).Element(
"LaboratoryOrderAndResult"
).Element(
"LaboratoryResultedTest"
).Element(
"CodeDescTxt"
).Value;
}
if
(!
string
.IsNullOrEmpty(resultVL))
{
if
(resultVL ==
"Viral Load"
)
{
ViralLoadCounter = xxd.SelectNodes(
"/Container/IndividualReport/Condition/LaboratoryReport/LaboratoryOrderAndResult/LaboratoryResultedTest/CodeDescTxt[. =\"Viral Load\"]"
).Count;
}
}
ws.Cells[t, 1].Value = file;
ws.Cells[t, 2].Value = HIVEnCounter;
ws.Cells[t, 3].Value = LaboratoryCounter;
ws.Cells[t, 4].Value = ViralLoadCounter;
ws.Cells[t, 5].Value = RegimenCounter1;
t = t + 1;
}
else
{
// Log error File is blank
}
}
please i need your help
Thank you all
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
sql trigger & c#
how i can connect to access data base?