如何查询文本文件? [英] How can I query a text file?

查看:67
本文介绍了如何查询文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人
我有从我们的一台服务器生成的此报告.基本上,该文件由多个配置文件"组成,每个配置文件具有多个应用程序,每个应用程序具有多个功能,某些功能具有权限.
问题在于当前格式的文件无法使我们执行任何查询,例如有多少配置文件具有"SWIFT FIN USER MT:+ 1%".

以下是包含多个配置文件的文件示例.

Dear all
I have this report generated from one of our servers. Basically, the file consists of a number of "profiles" each profile is having a number of applications, each application has a number of functions and some functions have permissions.
The problem is that the file in its present format does not enable us to do any queries, like how many profiles have "SWIFT FIN USER MT:+1%".

The following is a sample of the file containing a number of profiles.

<pre lang="css">Profile = EG_OPER_MT12479               

 
Application = Access Control            
Application = Correspondent Info        
Application = Mesg Creation             
Application = Mesg Modification         
Application = Message File              
Application = Access Control 
     Function = Signon                  
                Permissions =
                Start time:0001
                End time:2357
                Start time:2358
                End time:2359
                 
Application = Correspondent Info 
     Function = Open/Print Alias        
     Function = Open/Print Corr Dets    
     Function = Open/Print Country      
     Function = Open/Print Currency     
Application = Mesg Creation 
     Function = Add/Mod/Rem Template    
     Function = Create Message          
                Permissions =
                List of Own-Destination:+NSGBEGCX
                Can create broadcasting:N
                CCY/Amount:-
                Swift FIN User MT:+1%
                2%
                4%
                7%
                9%
                Swift FIN System MT:+
                Swift APC System MT:+
                Multiple Retrieval Allowed
                for FIN System mesg.:N
                Multiple Retrieval Allowed
                 for APC System mesg.:N
                FIN-Copy Allowed.:Y
                Create free format text Telex msg:N
                Create free format financial Telex msg:N
                 
     Function = Route Message           
Application = Mesg Modification 
     Function = Complete Message        
     Function = Modify Message          
                Permissions =
                Own destination:+NSGBEGCX
                Mod. in Text_modification:Y
                Mod. in Emission_security:N
                Mod. in Transmission_modif:N
                Mod. in modif_after_recept:N
                Mod. in Reception_security:N
                CCY/Amount:-
                Swift FIN User MT:+1%
                2%
                4%
                7%
                9%
                Swift FIN System MT:+
                Swift APC System MT:+
                Multiple Retrieval Allowed
                for FIN System mesg.:N
                Multiple Retrieval Allowed
                for APC System mesg.:N
                FIN-Copy Allowed.:Y
                 
     Function = Route Message           
Application = Message File 
     Function = Complete Instance       
     Function = Search                  
                Permissions =
                Completely hide messages of other units:Y
                 
      
Profile = EG_OPER_MT1249                

 
Application = Access Control            
Application = Correspondent Info        
Application = Mesg Creation             
Application = Mesg Modification         
Application = Message File              
Application = Access Control 
     Function = Signon                  
                Permissions =
                Start time:0001
                End time:2357
                Start time:2358
                End time:2359
                 
Application = Correspondent Info 
     Function = Open/Print Alias        
     Function = Open/Print Corr Dets    
     Function = Open/Print Country      
     Function = Open/Print Currency     
Application = Mesg Creation 
     Function = Add/Mod/Rem Template    
     Function = Create Message          
                Permissions =
                List of Own-Destination:+NSGBEGCX
                Can create broadcasting:N
                CCY/Amount:-
                Swift FIN User MT:+1%
                2%
                4%
                9%
                Swift FIN System MT:+
                Swift APC System MT:+
                Multiple Retrieval Allowed
                for FIN System mesg.:N
                Multiple Retrieval Allowed
                 for APC System mesg.:N
                FIN-Copy Allowed.:Y
                Create free format text Telex msg:N
                Create free format financial Telex msg:N
                 
     Function = Route Message           
Application = Mesg Modification 
     Function = Complete Message        
     Function = Modify Message          
                Permissions =
                Own destination:+NSGBEGCX
                Mod. in Text_modification:Y
                Mod. in Emission_security:N
                Mod. in Transmission_modif:N
                Mod. in modif_after_recept:N
                Mod. in Reception_security:N
                CCY/Amount:-
                Swift FIN User MT:+1%
                2%
                4%
                9%
                Swift FIN System MT:+
                Swift APC System MT:+
                Multiple Retrieval Allowed
                for FIN System mesg.:N
                Multiple Retrieval Allowed
                for APC System mesg.:N
                FIN-Copy Allowed.:Y
                 
     Function = Route Message           
Application = Message File 
     Function = Complete Instance       
     Function = Search                  
                Permissions =
                Completely hide messages of other units:Y
                 
      
Profile = EG_OPER_MT125                 

 
Application = Access Control            
Application = Correspondent Info        
Application = Mesg Creation             
Application = Mesg Modification         
Application = Message File              
Application = Access Control 
     Function = Signon                  
                Permissions =
                Start time:0001
                End time:2357
                Start time:2358
                End time:2359
                 
Application = Correspondent Info 
     Function = Open/Print Alias        
     Function = Open/Print Corr Dets    
     Function = Open/Print Country      
     Function = Open/Print Currency     
Application = Mesg Creation 
     Function = Add/Mod/Rem Template    
     Function = Create Message          
                Permissions =
                List of Own-Destination:+NSGBEGCX
                Can create broadcasting:N
                CCY/Amount:-
                Swift FIN User MT:+198
                298
                535
                Swift FIN System MT:+
                Swift APC System MT:+
                Multiple Retrieval Allowed
                for FIN System mesg.:N
                Multiple Retrieval Allowed
                 for APC System mesg.:N
                FIN-Copy Allowed.:Y
                Create free format text Telex msg:N
                Create free format financial Telex msg:N
                 
     Function = Route Message           
Application = Mesg Modification 
     Function = Complete Message        
     Function = Modify Message          
                Permissions =
                Own destination:+NSGBEGCX
                Mod. in Text_modification:Y
                Mod. in Emission_security:N
                Mod. in Transmission_modif:N
                Mod. in modif_after_recept:N
                Mod. in Reception_security:N
                CCY/Amount:-
                Swift FIN User MT:+198
                298
                535
                Swift FIN System MT:+
                Swift APC System MT:+
                Multiple Retrieval Allowed
                for FIN System mesg.:N
                Multiple Retrieval Allowed
                for APC System mesg.:N
                FIN-Copy Allowed.:Y
                 
     Function = Route Message           
Application = Message File 
     Function = Complete Instance       
     Function = Search                  
                Permissions =
                Completely hide messages of other units:Y
                 
      
Profile = EG_OPER_MT1279                

 
Application = Access Control            
Application = Correspondent Info        
Application = Mesg Creation             
Application = Mesg Modification         
Application = Message File              
Application = Access Control 
     Function = Signon                  
                Permissions =
                Start time:0001
                End time:2357
                Start time:2358
                End time:2359
                 
Application = Correspondent Info 
     Function = Open/Print Alias        
     Function = Open/Print Corr Dets    
     Function = Open/Print Country      
     Function = Open/Print Currency     
Application = Mesg Creation 
     Function = Add/Mod/Rem Template    
     Function = Create Message          
                Permissions =
                List of Own-Destination:+NSGBEGCX
                Can create broadcasting:N
                CCY/Amount:-
                Swift FIN User MT:+1%
                2%
                7%
                9%
                Swift FIN System MT:+
                Swift APC System MT:+
                Multiple Retrieval Allowed
                for FIN System mesg.:N
                Multiple Retrieval Allowed
                 for APC System mesg.:N
                FIN-Copy Allowed.:Y
                Create free format text Telex msg:N
                Create free format financial Telex msg:N
                 
     Function = Route Message           
Application = Mesg Modification 
     Function = Complete Message        
     Function = Modify Message          
                Permissions =
                Own destination:+NSGBEGCX
                Mod. in Text_modification:Y
                Mod. in Emission_security:N
                Mod. in Transmission_modif:N
                Mod. in modif_after_recept:N
                Mod. in Reception_security:N
                CCY/Amount:-
                Swift FIN User MT:+1%
                2%
                7%
                9%
                Swift FIN System MT:+
                Swift APC System MT:+
                Multiple Retrieval Allowed
                for FIN System mesg.:N
                Multiple Retrieval Allowed
                for APC System mesg.:N
                FIN-Copy Allowed.:Y
                 
     Function = Route Message           
Application = Message File 
     Function = Complete Instance       
     Function = Search                  
                Permissions =
                Completely hide messages of other units:Y




我想到了将其转换为XML文件的想法,也想到了使用C#在其上运行正则表达式并将结果存储在数据库中的方法,但我都失败了.
您认为做手头任务最有效的方法是什么?
任何帮助将不胜感激.

谢谢回复.问题(无论使用XML方法还是RegEx方法)都是我想动态解析文档的问题.我需要一种阅读文档并将不同部分存储在字段中的方法,以便可以查询它们.




I thought of converting it to an XML file, i also thought of running regular expressions on it with C# and storing the results in a database but i failed in both.
What do you think is the most efficient way to do the task at hand ?
Any help would be greatly appreciated.

Thanks for the reply. The problem (whether using the XML approach or the RegEx approach) is that i want to parse the document on the fly. I need a way to read the document and store the different parts in fields so that they can be queried.

推荐答案

我会使用XDocument来查找xml. />
我还将创建一个保存配置文件数据的类.
一个用于应用程序.
功能之一.
以及一个用于完善功能的类或枚举.

所以最后一堂课看起来像这样:

I would go for the xml using XDocument.

I would also create a Class that holds the profile Data.
One for the Application.
One for the Function(s).
And one class or enum for the permision of the function(s).

So the final class would look something like this:

public class Profile{
     List<Application> apps = new List&lt;Application&gt;;
     
     //a list of Function for application. In the function class
     //put an Application field to make the link wich func belongs
     //to wich app.
     
     //and finally permison(s)
}



因此xml如下所示:



So the xml would be something like this:

<Profiles>
  <Profile>
   <Application>"myApp"
      <Funtion>
         <Permision></Permision>
      </Function>
   </Application>   
  </Profile>
</Profiles>



因此,您可以使用XLINQ来获取数据. Ex以获取给定应用程序的所有功能:



So you could use XLINQ to get the datas. Ex to get all the functions of a given Application:

XDocument xdoc = XDocument.Load("YourFileName");
           var myAppFunction = xdoc.Elements("Profiles").Elements("Profile").
               Elements("Application").
               Where(n=>n.Value=="myApp").Elements("Function");                



您说失败了.如何?为什么?什么?



You said that it failed. How? Why? What?


这篇关于如何查询文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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