开发者

How to update an empty node using Xpath navigator

i have an XML like this

<main>
  <reportPath>d:\reports</reportPath>
  <errorPath>D:\Error</errorPath>
  <project>D:\xyz.txt</project>
  <value />
</main>

here "value" is an empty node. using Xpath navigator, I am able to reach Value node, but not able update it. using something like :

XPathNavigator currentnavigator = navigator.SelectSingleNode("//*/value");

Can anyone give me some idea how to edit this node i.e. add value to it which can be a string path.

will get appended a开发者_Go百科t the end ?


If your navigator is editable, you can just use SetValue():

currentnavigator.SetValue("somePath");

That being said, I would recommend you to use LINQ to XML instead, I find it much easier to use:

XDocument doc = …;
doc.Root.Element("value").Value = "somePath";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜