TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Abraham Olatubosun
NA
471
114.7k
CONVERTING DATE TO dd/mm/yyyy IN XML
Mar 20 2016 12:45 AM
Hello All,
I need your help friends
I wrote a code that will extract records from
SQL TABLE
and use dataset to write it to
XML
, but i encounter a date convertion challenge after writting the XML the date change from
dd/mm/yyyy to yyyy-mm-ddT00:00:00+00
, in the process of correcting this, i found this code
www.c-sharpcorner.com
//XMLTextReader
//Reads the Xml data generated by DataSet
XmlTextReader XTReader = new XmlTextReader(ds1.GetXml(), XmlNodeType.Element, null);
//XMLTextWriter
//To write data into xml file
XmlTextWriter XTWriter = new XmlTextWriter(directoryPath + Tfilename.Trim() + ".xml", Encoding.UTF8);
XTWriter.WriteStartDocument();
string fieldName = "";
while (XTReader.Read())
{
switch (XTReader.NodeType)
{
//Check for the Node Name
case XmlNodeType.Element:
XTWriter.WriteStartElement(XTReader.Name);
fieldName = XTReader.Name;
break;
//Check for the Node Value
case XmlNodeType.Text:
//If the NodeName is PubDate
string Fname = "";
foreach (string mList in mFieldname)
{
Fname = mList.ToString().ToLower();
if (fieldName.ToLower() == Fname)
break;
}
if (fieldName.ToLower() == Fname)
//if (fieldName.ToLower() == SearchDate.ToLower())
{
DateTime dt = DateTime.Parse(XTReader.Value.ToString());
//Here the DateTime can be changed to any format as
//MM-dd-yyyy or dd-MM-yyyy or .ToShortDateString() ...
XTWriter.WriteString(dt.ToString("dd/MM/yyyy"));
}
else
XTWriter.WriteString(XTReader.Value);
// break;
//}
break;
case XmlNodeType.EndElement:
XTWriter.WriteEndElement();
break;
} //switch
} // while
XTWriter.Close();
this code worked fine in converting the date to british-UK format, The issue now is, it is changing the XML file from vertical arrengment to horizontal making hard to read bellow is the result:
<?xml version="1.0" encoding="utf-8"?><NewDataSet><PatientDemographics_Record><Lastname>Hidden</Lastname><Firstname>Hidden</Firstname><ClinicalVisit6MonthsPriorToReview>Yes</ClinicalVisit6MonthsPriorToReview><MaritalStatus>MARRIED</MaritalStatus><HosiptalNo>Null</HosiptalNo><RNL_SerialNO>263</RNL_SerialNO><Gender>Male</Gender><DateofBirth>11/01/1976</DateofBirth><AGE>40</AGE><HospitalAdmissionDuringReview>Null</HospitalAdmissionDuringReview><Occupation>Employed</Occupation><Education>Junior Secondary</Education><WardVillageTown_OfResidence><LGA_OfResidence>UDI</LGA_OfResidence><State_OfResidence>ENUGU</State_OfResidence><State_OfOrigin>ENUGU</State_OfOrigin><Tribe>IBO</Tribe><FacilityID>1416110036</FacilityID><PatientID>02371</PatientID><DateEnrolled>28/05/2015</DateEnrolled><RecordCompletionPosition>16</RecordCompletionPosition><UploaderId>Null</UploaderId><UploaderDT>01/01/1999</UploaderDT><webUploadFlag>NO</webUploadFlag><ReviewPeriod>6</ReviewPeriod><ART_Start_Date>01/07/2015</ART_Start_Date><ptn_pk>5988</ptn_pk></WardVillageTown_OfResidence><PatientDemographics_Record><Lastname>Hidden</Lastname><Firstname>Hidden</Firstname><ClinicalVisit6MonthsPriorToReview>Yes</ClinicalVisit6MonthsPriorToReview><MaritalStatus>MARRIED</MaritalStatus><HosiptalNo>Null</HosiptalNo><RNL_SerialNO>574</RNL_SerialNO><Gender>Male</Gender><DateofBirth>11/04/1979</DateofBirth><AGE>36</AGE><HospitalAdmissionDuringReview>Null</HospitalAdmissionDuringReview><Occupation>Employed</Occupation><Education>Junior Secondary</Education><WardVillageTown_OfResidence>AWKUNTO</WardVillageTown_OfResidence><LGA_OfResidence>UDI</LGA_OfResidence><State_OfResidence>ENUGU</State_OfResidence><State_OfOrigin>ENUGU</State_OfOrigin><Tribe>IBO</Tribe><FacilityID>1416110036</FacilityID><PatientID>02348</PatientID><DateEnrolled>28/04/2015</DateEnrolled><RecordCompletionPosition>16</RecordCompletionPosition><UploaderId>Null</UploaderId><UploaderDT>01/01/1999</UploaderDT><webUploadFlag>NO</webUploadFlag><ReviewPeriod>6</ReviewPeriod><ART_Start_Date>24/11/2015</ART_Start_Date><ptn_pk>5916</ptn_pk></PatientDemographics_Record><PatientDemographics_Record><Lastname>Hidden</Lastname><Firstname>Hidden</Firstname><ClinicalVisit6MonthsPriorToReview>Yes</ClinicalVisit6MonthsPriorToReview><MaritalStatus>MARRIED</MaritalStatus><HosiptalNo>Null</HosiptalNo><RNL_SerialNO>784</RNL_SerialNO><Gender>Female</Gender><DateofBirth>01/03/1990</DateofBirth><AGE>26</AGE><HospitalAdmissionDuringReview>Null</HospitalAdmissionDuringReview><Occupation>Employed</Occupation><Education>Junior Secondary</Education><WardVillageTown_OfResidence><LGA_OfResidence>UDI</LGA_OfResidence><State_OfResidence>ENUGU</State_OfResidence><State_OfOrigin>ENUGU</State_OfOrigin><Tribe>IBO</Tribe><FacilityID>1416110036</FacilityID><PatientID>02287</PatientID><DateEnrolled>17/02/2015</DateEnrolled><RecordCompletionPosition>16</RecordCompletionPosition><UploaderId>Null</UploaderId><UploaderDT>01/01/1999</UploaderDT><webUploadFlag>NO</webUploadFlag><ReviewPeriod>6</ReviewPeriod><ART_Start_Date>20/10/2015</ART_Start_Date><ptn_pk>6470</ptn_pk></WardVillageTown_OfResidence><PatientDemographics_Record><Lastname>Hidden</Lastname><Firstname>Hidden</Firstname><ClinicalVisit6MonthsPriorToReview>Yes</ClinicalVisit6MonthsPriorToReview><MaritalStatus>MARRIED</MaritalStatus><HosiptalNo>Null</HosiptalNo><RNL_SerialNO>842</RNL_SerialNO><Gender>Male</Gender><DateofBirth>15/05/1985</DateofBirth><AGE>30</AGE><HospitalAdmissionDuringReview>Null</HospitalAdmissionDuringReview><Occupation>Employed</Occupation><Education>Junior Secondary</Education><WardVillageTown_OfResidence>ATANI AROCHUKWU</WardVillageTown_OfResidence><LGA_OfResidence>UDI</LGA_OfResidence><State_OfResidence>IMO</State_OfResidence><State_OfOrigin>IMO</State_OfOrigin><Tribe>IBO</Tribe><FacilityID>1416110036</FacilityID><PatientID>01549</PatientID><DateEnrolled>01/11/2011</DateEnrolled><RecordCompletionPosition>16</RecordCompletionPosition><UploaderId>Null</UploaderId><UploaderDT>01/01/1999</UploaderDT><webUploadFlag>NO</webUploadFlag><ReviewPeriod>6</ReviewPeriod><ART_Start_Date>21/07/2015</ART_Start_Date><ptn_pk>4690</ptn_pk>
</PatientDemographics_Record></PatientDemographics_Record></PatientDemographics_Record>
</NewDataSet>
Attachment:
helpme.zip
Reply
Answers (
2
)
How to Count Number of lines in C# console application?
The mapping of CLR type to EDM type is ambiguous