| | |
Trying to iterate through XML files
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2008
Posts: 6
Reputation:
Solved Threads: 0
I would like ask for some advice please, I am trying to create a program in C# but have the following problem. I am currently trying to loop through a batch of XML files that are stored in a folder. However, I just don't want to loop through the XML file name, as I need to check through all the nodes in each XML file(650 files) for certain values. I know how to loop through a specific Xml file but unsure of how to actually loop through all XMl files to retrieve the values inside the values. For now, all I have is code to read through a specific XML file as shown below. I would be grateful for any assistance in this matter.
c# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Xml; using System.IO; using System.Xml.Linq; namespace VoteProg_1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } XmlTextReader XReader = new XmlTextReader ("C:\\Users\\Mark\\Documents\\VoteResults2\\result001.xml"); private void label1_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { foreach (string fileName in XFiles) { while (XReader.Read()) { switch (XReader.NodeType) { case XmlNodeType.Element: // The node is an element. textBox1.Text = XReader.Name.ToString(); break; case XmlNodeType.Text: //Display the text in each element. textBox1.Text = XReader.Value.ToString(); break; case XmlNodeType.EndElement: //Display the end of the element. textBox1.Text = XReader.Name.ToString(); break; } } } // textBox1.Text = XmlStr.ToString(); } } private void label13_Click(object sender, EventArgs e) { } private void Form1_Load(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { } } }
Last edited by peter_budo; Nov 2nd, 2009 at 7:25 pm. Reason: Correcting code tags
•
•
Join Date: Oct 2009
Posts: 92
Reputation:
Solved Threads: 8
0
#2 Nov 1st, 2009
It sounds as if you just need to iterate through files in a directory.
Here is an example of that:
Here is an example of that:
C# Syntax (Toggle Plain Text)
using System; using System.IO; namespace DW_FileLoop { class Program { static void Main(string[] args) { string strRootDir = @"C:\Users\Mark\Documents\VoteResults2"; string[] arr_strFiles = Directory.GetFiles(strRootDir, "*.xml"); foreach (string strFile in arr_strFiles) { Console.WriteLine("Processing: " + strFile); //Call XML Processor here. } } } }
![]() |
Other Threads in the C# Forum
- Previous Thread: Tables
- Next Thread: send sms with c#.net
| Thread Tools | Search this Thread |
.net access ado.net algorithm alignment array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox control conversion csharp custom customactiondata database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ hospitalmanagementsystems httpwebrequest image index input install java label list listbox listener mandelbrot math mono mouseclick mysql networking operator path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





