开发者

How to update an empty node using Xpath navigator

开发者 https://www.devze.com 2023-04-03 20:52 出处:网络
i have an XML like this <main> <reportPath>d:\\reports</reportPath> <errorPath>D:\\Error</errorPath>

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

精彩评论

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

关注公众号