0
나와 프로그래밍 기술이 절실합니다. 내 C 드라이브에서 여러 xml 워드 프로세서를로드 할 수 있지만 루프에 무언가를 넣을 수있는 방법을 찾아서 첫 번째 코드가 아닌 모든 XML 코드를 구문 분석 할 수 있어야합니다.xmldocument를 사용하여 여러 xml 파일을 구문 분석 C#
using System;
using System.IO;
using System.Xml;
public class Program
{
public static void Main()
{
string[] filePaths = Directory.GetFiles(@"C:\Users\r626890\Documents\BoxTesting\", "*.xml");
foreach (string files in filePaths)
Console.WriteLine("'{0}'",files);
Console.WriteLine();
XmlDocument doc = new XmlDocument();
string file = filePaths[0].ToString();
XmlNodeList xmlnode;
doc.Load(file);
XmlNodeList indexValue = doc.GetElementsByTagName("Index");
for (int i = 0; i < indexValue.Count; i++)
{
Console.WriteLine();
Console.WriteLine("Description: {0} ", indexValue[i].ChildNodes.Item(0).InnerXml);
Console.WriteLine("Value: {0} ", indexValue[i].ChildNodes.Item(1).InnerXml);
// Console.WriteLine("{0}",i);
}
xmlnode = doc.GetElementsByTagName("FileName");
for (int i = 0; i < xmlnode.Count; i++)
{
// Console.WriteLine("URI: {0} ", elemList[i].InnerXml.Split('_')[0]);
Console.WriteLine();
Console.WriteLine("Type: {0} ", xmlnode[i].InnerXml.Split('_')[1]);
Console.WriteLine();
Console.WriteLine("File Name: {0} ", xmlnode[i].InnerXml);
Console.WriteLine("------------------------------------------------------------");
Console.WriteLine("(Total # of files: {0})", ++i);
}
Console.ReadLine();
}
}
확실히 해결했습니다. 전체 내용을 foreach 루프에 넣는 것이 좋습니다. 또 다른 질문은 ... 각 파일 수를 어떻게 표시 할 수 있습니까? – user3806259
개수를 유지하려면 foreach 대신 for : int (int i = 0; i
csblo
완벽! 도움을 감사하십시오 !! – user3806259