如何从XML文件中搜索特定值并进行更新. [英] How Can I search a Particular Value From XML file and Update it.

查看:74
本文介绍了如何从XML文件中搜索特定值并进行更新.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从XML文件中搜索特定值.
以下是我的XML的结构.
我有一个TextBox和一个按钮
我想阅读第
节的值 service updateinterval ="0.00:02:00"
表示我只想获取值 0.00:02:00
在文本框中.
然后要在输入其他一些值后对其进行更新.

How Can I search a Particular Value From XML file.
Below is the Structure of My XML.
I have a from having TextBox and a Button
I want to read the Value of Section
service updateinterval="0.00:02:00"
means I just Want to Fetch the Value 0.00:02:00
in textbox.
and then want to update it after entering some other values.

<configuration>
  <configSections>
    <section name="" type=", " />
    <section name="" type="" />
    <section name="" type="" />
    <section name="" type=", , Version=, Culture=, PublicKeyToken=" />
  </configSections>
  <Service1>
    <applications>
      <application id="" manifestUri="" location="" />
      <applicationexe value=",,,,," />
    </applications>
  </Service1>
  <Service21>
    <applications>
      <application id="" manifestUri="" location="" />
      <applicationexe value=",,,,," />
    </applications>
  </Service21>
  <UpdaterConfiguration defaultDownloader="" applicationId="" basePath="">
    <downloaders>
      <add name="" type="," authenticationScheme="" targetServerType="" />
    </downloaders>
    <service updateInterval="0.00:02:00" />
  </UpdaterConfiguration>
  <securityCryptographyConfiguration>
    <hashProviders>
      <add algorithmType=", , Version=, Culture=, PublicKeyToken=" saltEnabled="" type="" />
    </hashProviders>
  </securityCryptographyConfiguration>
</configuration>



请协助
我该怎么做



Please assist
how Can I do this

推荐答案

我只知道c#,但是那是唯一的语法!如果您不使用LinQ,请使用以下逻辑,您可以尝试按照以下说明读取值. (如果使用LinQ,请告诉我.)

I know only c#, but the that''s only syntax ! Use following logic if you NOT using LinQ, you can try following to read value. (If using LinQ, let me know).

XmlDcoument xDoc = new XmlDocument();
xDoc.Load("YourXml.XML");

XmlNode xNode = xDoc.DocumentElement.SelectSingleNode("UpdaterConfiguration/service");
string value = xNode.Attributes["updateInterval"].Value;



使用此值分配给textBox.

更新值(在单独的事件中考虑其值)



Use this value to assign to textBox.

To update the value (considering its in separate event)

XmlDcoument xDoc = new XmlDocument();
xDoc.Load("YourXml.XML");

XmlNode xNode = xDoc.DocumentElement.SelectSingleNode("UpdaterConfiguration/service");
xNode.Attributes["updateInterval"].Value = "NewValue";



希望有帮助.

谢谢
Milind



Hope that helps.

Thanks
Milind


这篇关于如何从XML文件中搜索特定值并进行更新.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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