I have multiple .xml files, all of them having the same node names but different values. Example:
File1.xml has the following contents:
<?xml version="1.0"?><Data><Waf>No</Waf><Name>TEMP\1</Name><Number>0</Number><Iteration>1</Iteration><Lot> </Lot><DateAndTime>11:36:24:35 10/8/2019</DateAndTime><Id>5555</Id><SW>6.40.22.10900</SW><Image>Reference Point 750</Image><Angle >0</Angle ><Algo></Algo></Data>
Similarly, File2.xml has:
<?xml version="1.0"?><Data><Waf>Yes</Waf><Name>TEMP\2</Name><Number>10</Number><Iteration>6</Iteration><Lot>99</Lot><DateAndTime>11:36:49:35 10/8/2019</DateAndTime><Id></Id><SW>6.40.22.10900</SW><Image>Reference Point 90</Image><Angle >180</Angle ><Algo></Algo></Data>
I use C# (Visual Studio 2010); my goal is to obtain a .csv / .txt file which has first row:
Waf, Name, Number, Iteration, Lot, DateAndTime, Id, SW, Image, Angle, Algo
No, TEMP\1, 0, 1, - , 11:36:24:35 10/8/2019, 5555, 6.40.22.10900, Reference Point 750, 0, -
Yes, TEMP\2 , 10, 6, 99, 11:36:49:35 10/8/2019, -, 6.40.22.10900, Reference Point 90, 180, -
The input to my algorithm would be the name of xml files. These are the steps I have done till now:
for (idx = 0; idx < num_files; idx++)
{
file_name = file_name + ".xml"; // this contains the name of xml file
if (idx == 0) // if I'm reading the first xml file, make a note of all the node names since they will be the column headers.
{
fs = new FileStream(location_xml_file, FileMode.Open, FileAccess.Read);
xmldoc.Load(fs);
xml_num_nodes = xmldoc.n ; //.Count;
Console.Write("\n xml_num_nodes = {0}", xml_num_nodes);
}
}
However,
- The number of nodes xml_num_nodes is output as 2.
- I think that it's unnecessary for me to write this code from scratch and there must be as easier way. If so, what am I missing? I am using Linq and saw a fer resources but I'm not able to get what I want.