从文件夹加载多个xml文档 [英] loading multiple xml documents from folder

查看:65
本文介绍了从文件夹加载多个xml文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅在一周前才开始使用C#. 开发适配器/程序来处理文件夹中的xml文档并将输出写入excel文件. 我能够完成任务-使用xml,xml.linq类. -现在,我已经着手使流程自动化. (这样我就可以专注于任务的第二部分,处理一组.DAT文件)

started working on C# only a week ago. developing an adapter/program to process xml documents from a folder and writing the output to an excel file. i am able to achieve the task - used the xml, xml.linq classes. - now i have setout myself to automate the process. (so that i can focus on the second part of my task, process a set of .DAT files)

在上述任务中,我一次读取了每个文档,然后通过类似类型的xml联合"(其中一些被拆分为多个文件),然后对其进行处理.

in the above task i read each document at a time then "union" over similar type of xml's - (some of them are split over multiple files) then process them.

我想对我的程序做的就是将xml文档转移到共享文件夹(windows)中-我希望程序开始处理xml文件并将过程的输出写入excel文件

What I would like to do with my program is as soon as the xml documents are transferred to a shared folder(windows) - i would like the program to start processing the xml files and write the output of the process to excel file.

任何指针-对于要查找的内容都会有很大帮助.

any pointers - as to what to look for would be of great help.

           ************************(update)[ratna:11th Aug 2011,6AM IST]

            **********************************sample code**************
class FM
{
static void Main(string[] args)
         {

             FM LetsLoad = new FM();
             IEnumerable<XElement> loadedcustDoc = LetsLoad.LoadCustDocuments();

            Cust checkCustTrav = new Cust();
            checkCustTrav.CustTrav(loadedcustDoc);
            /*   to process the loaded documents and to output result to excel
            *
                      */

        //Console.ReadLine();
         }

        public IEnumerable<XElement> LoadCustDocuments()
        { 
            // Loading Customer **** Start***
            XDocument CustDoc1 = XDocument.Load(@"J:\dot\custtemp1.xml");
    XDocument CustDoc2 = XDocument.Load(@"J:\dot\custtemp2.xml");


            IEnumerable<XElement> CustEList1 = CustDoc1.Root.Descendants("Customer");
            IEnumerable<XElement> CustEList2 = CustDoc2.Root.Descendants("Customer");
            IEnumerable<XElement> CustEListComb = CustEList1.Union(CustEList2)
            return CustEListComb;
        }
 }  

** * ** * ** * ** * ** * ** * * 示例代码结尾 **** 谢谢大家提供的意见. 是的,我想在文件夹中查看添加的文档. 添加文档后,加载文档进行处理. 此示例中的Cust类处理该处理. 我想自动执行LoadCustDocuments以便读取所有XML的方法,并且只加载文件名中带有"cust"的文件,将它们与"Union"组合到一个IEnumerable中,然后返回以进行处理.最好的负载方式]

*******************sample code end**** thank you all for the inputs provided. yes, I would like to watch the folder for documents added. once the documents are added, load the documents for processing. the processing is handled by Cust class in this sample. the LoadCustDocuments is the method i would like to automate in order to read through all the XML's , and only load files with "cust" in file name, combine them with "Union" into one IEnumerable and return for processing.[assuming this being the best way to do the load]

我将仔细阅读所提供的输入,然后回发.

I will be reading through the inputs provided, and post back.

推荐答案

您是否正在寻找这非常适合您在等待文件出现在文件夹中的情况.

This is perfect for situations where you are waiting for a file to appear in a folder.

这篇关于从文件夹加载多个xml文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆