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:
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Abraham OlatubosunPosted Mar 20, 2016, 8:35 AM
Joginder BangerPosted Mar 20, 2016, 7:04 AM