LINQ To XML - 如何读取此 XML?
我有一个如下所示的 XML 文件:
...
<body>
<unit id="1" name ="xxx">
<sourceFile>SomeFile.xml</sourceFile>
<targetFile/>
</unit>
<unit id="2" name ="xxx">
<sourceFile>SomeFile.xml</sourceFile>
<targetFile/>
</unit>
</body>
有人可以告诉我如何通过 C# 使用 LINQ to XML 来读取 sourceFile 节点的值,并更新 targetFile 的值,因为我不熟悉 LINQ to XML ?
谢谢。
I've got an XML file that looks like this:
...
<body>
<unit id="1" name ="xxx">
<sourceFile>SomeFile.xml</sourceFile>
<targetFile/>
</unit>
<unit id="2" name ="xxx">
<sourceFile>SomeFile.xml</sourceFile>
<targetFile/>
</unit>
</body>
Can someone show me how I would use LINQ to XML via C# to read the value of the sourceFile node, and update the value of targetFile as I'm not familiar with LINQ to XML?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样的东西:
或者:(当然
,如果您想保存回文件,请随后调用 doc.Save ,正如另一个答案中指出的那样。)
Something like this:
Alternatively:
(And call
doc.Save
afterwards if you want to save back to a file, of course, as pointed out in another answer.)要更新实际文件本身,您只需对加载的文档调用 Save() 方法。
To update the actual file itself, you just need to call the Save() method on the loaded document.