简体   繁体   English

如何从XML或文本文件读取特定数据?

[英]How can I read specific data from XML or Text files?

I want to store user data in a XML or text file. 我想将用户数据存储在XML或文本文件中。 I know how to write data into a file, the problem I have is reading that data and getting what I want out of it. 我知道如何将数据写入文件,我遇到的问题是读取数据并从中获取所需信息。

I want to store a MySQL connection string with my own custom data. 我想用自己的自定义数据存储一个MySQL连接字符串。 For example... 例如...

 "Name=Localhost;CoreVerr=5.x;Server=127.0.0.1;Port=3306;Uid=root;Password=root;Database=accounts;"

Note that the custom data is "Name" and "CoreVerr" as these are not found in a normal MySQL connection string. 请注意,自定义数据是“名称”和“ CoreVerr”,因为在常规的MySQL连接字符串中找不到这些数据。

Now I want to read data from "Name" and "CoreVerr". 现在,我想从“名称”和“ CoreVerr”读取数据。 So the output would then be, 'Localhost', '5.x'. 因此输出将是“ Localhost”,“ 5.x”。 How could I do this? 我该怎么办? Thanks. 谢谢。

It sounds like you are looking for application and user settings . 听起来您正在寻找应用程序和用户设置

Settings allow you to specify configuration values in setting files and provide easy access. 设置允许您在设置文件中指定配置值,并可以轻松访问。

You can use the XmlDocument class to do this in C#. 您可以使用XmlDocument类在C#中执行此操作。 https://msdn.microsoft.com/en-us/library/system.xml.xmldocument%28v=vs.110%29.aspx https://msdn.microsoft.com/zh-CN/library/system.xml.xmldocument%28v=vs.110%29.aspx

This allows you to target specific nodes and attributes within your XML document once you have loaded it and extract the information required. 一旦加载XML文档并提取所需的信息,这将使您能够定位XML文档中的特定节点和属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM