<AnswerSet>
<Answer name="es/21-9-c">
<TextValue>420 Quincy St.</TextValue>
</Answer>
<Answer name="rptmc/programtype">
<MCValue>
<SelValue>VS</SelValue>
</MCValue>
</Answer>
<Answer name="programtype">
<MCValue>
<SelValue>AS</SelValue>
<SelValue>BS</SelValue>
<SelValue>CS</SelValue>
<SelValue>Ron</SelValue>
<SelValue>Deepak</SelValue>
<SelValue>Nelson</SelValue>
</MCValue>
</Answer>
</AnswerSet>
public class AnswerFile
{
public string txt_DSCL_COLUMN_NAME { get; set; }
public string int_DSCL_VARIABLE_TYPE_ID { get; set; }
public DateTime dat_DSCL_CREATED_DATE { get; set; }
public string txt_DSVL_VALUE { get; set; }
}
string getXmlPath = @"C:\DA_Portal\ClientFiles\3977034278\DownloadedDataSets\10-16-12\Transformed\";
System.Collections.Generic.List<FileInfo> _theFiles;
_theFiles = Utility.GetFiles(getXmlPath, "xml");
int totalFiles = _theFiles.Count;
foreach (FileInfo AnswerFileInfo in _theFiles)
{
XDocument obAnsFile;
string AnswerFileName = AnswerFileInfo.Name;
obAnsFile = new XDocument();
obAnsFile = Xdocument.Load(AnswerFileInfo.FullName);
IEnumerable<AnswerFile> Answers = (from e in obAnsFile.Descendants("Answer")
select new AnswerFile
{
txt_DSCL_COLUMN_NAME = e.Attribute("name").Value,
txt_DSVL_VALUE = (string)e.Element("MCValue").Value.Insert(e.Element("MCValue").Value.Length, "|"),
dat_DSCL_CREATED_DATE = DateTime.Now,
int_DSCL_VARIABLE_TYPE_ID = e.FirstNode != null ? ((XElement)e.FirstNode).Name.LocalName : "hello",
}).ToList();
The Output I want is should be in this format
For this
<Answer name="es/21-9-c">
<TextValue>420 Quincy St.</TextValue>
</Answer>
txt_DSCL_COLUMN_NAME ="es/21-9-c"
int_DSCL_VARIABLE_TYPE_ID ="TextValue"
dat_DSCL_CREATED_DATE="26/10/2012"
txt_DSVL_VALUE ="420 Quincy St."
--------------------------------------------
<Answer name="rptmc/programtype">
<MCValue>
<SelValue>VS</SelValue>
</MCValue>
</Answer>
txt_DSCL_COLUMN_NAME ="rptmc/programtype"
int_DSCL_VARIABLE_TYPE_ID ="MCValue"
dat_DSCL_CREATED_DATE="26/10/2012"
txt_DSVL_VALUE ="VS"
<Answer name="programtype">
<MCValue>
<SelValue>AS</SelValue>
<SelValue>BS</SelValue>
<SelValue>CS</SelValue>
<SelValue>Ron</SelValue>
<SelValue>Deepak</SelValue>
<SelValue>Nelson</SelValue>
</MCValue>
</Answer>
txt_DSCL_COLUMN_NAME ="programtype"
int_DSCL_VARIABLE_TYPE_ID ="MCValue"
dat_DSCL_CREATED_DATE="26/10/2012"
txt_DSVL_VALUE ="VS|BS|CS|Ron|Deepak|Nelson"
Kindly let me know if the things are not clear
LINQ TO XML
Page 1 of 10 Replies - 902 Views - Last Post: 26 October 2012 - 03:59 AM
#1
LINQ TO XML
Posted 26 October 2012 - 03:59 AM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote


|