0

我正在尝试向其中的所有类似节点插入一些一致的值。示例xml如下:

 <DrWatson>
  <Bugs Name="Bug.add --> Nirvananaaaaaaaaaaaaaaa">
    <Bug>
      <family>ESG</family>
      <product>Dr.Watson</product>
      <version>Xpress API</version>
      <productarea>1</productarea>
      <subarea>Blank</subarea>
      <title>Bug.AddNote#1 : Dr.Watson Framework by Aman</title>
      <description>test</description>
      <appLanguages>English~~Bug</appLanguages>
      <platforms>Win XP All~~English~~Bug</platforms>
      <state>Open</state>
      <status>NeedsReview</status>
      <reason>Blank</reason>
      <failureType>Unspecified</failureType>
      <Frequency>Unknown</Frequency>
      <severity>0</severity>
      <priority>0</priority>
      <methodFound>Blank</methodFound>
      <foundInBuild>1</foundInBuild>
      <dev>bansal</dev>
      <qe>sdawar</qe>
      <keyword>Blank</keyword>
      <duplicateId>Blank</duplicateId>
      <note></note>
    </Bug>
    <Bug>
      <family>ESG</family>
      <product>Dr.Watson</product>
      <version>Xpress API</version>
      <productarea>1</productarea>
      <subarea>Blank</subarea>
      <title>Bug.AddNote#1 : Dr.Watson Framework by Aman</title>
      <description>test</description>
      <appLanguages>English~~Bug</appLanguages>
      <platforms>Win XP All~~English~~Bug</platforms>
      <state>Open</state>
      <status>ToFix</status>
      <reason>Blank</reason>
      <failureType>Unspecified</failureType>
      <Frequency>Unknown</Frequency>
      <severity>0</severity>
      <priority>0</priority>
      <methodFound>Blank</methodFound>
      <foundInBuild>1</foundInBuild>
      <dev>bansal</dev>
      <qe>sdawar</qe>
      <keyword>Blank</keyword>
      <duplicateId>Blank</duplicateId>
      <note></note>
    </Bug>
  </Bugs>
</DrWatson>

我想替换<foundinBuild>标签的值。另外,请注意,我不想保存编辑,但会在运行时使用编辑后的 ​​xml,以便在我的代码中进一步使用。请提出一些解决方法。

4

1 回答 1

0

尝试这个

      var doc = new XmlDocument();
            doc.Load("Your XML Path");
            XmlElement root = doc.DocumentElement;
            XmlNodeList nodes = root.SelectNodes("Bugs/Bug");                
            foreach (XmlNode node in nodes)
            {                 
                    node["foundInBuild"].InnerText = "Your New Value";                   
            }
于 2013-09-12T08:57:48.570 回答