如何在c#中生成自定义XML节点ID [英] How can I generate custom XML Nodes ID in c#
问题描述
大家好。
首先,请原谅我的英语,我会尽力解释这个问题。
我是程序员的初学者,我在项目中需要帮助。
我一直在互联网上搜索如何重命名XML节点的ID,但我找不到我需要的东西。
例如:如果我有节点星期一和ID1,我想更改它为
ID为48或星期一。
是否有可能,c#中有任何函数或库吗?
如果有人知道怎么做,我将非常感激。
感谢和来自西班牙
Hello everyone.
First of all, excuse my english, i'll try to explain the question the best i can.
I'm a beginner in programation an i need help in a proyect.
I've been searching on the internet about how to rename the ID of the XML nodes but i didn't find what i need.
For example: if i have the Node "Monday" and the ID "1" and i want to change it for
the ID "48" or "Mon".
Is it possible, are there any function or library in c# to do it?
If anyone knows how to do it i'll be very grateful.
Thanks and regards from Spain¡
推荐答案
试试这个
try this
var doc = XDocument.Load("test.xml");
doc.Root.Element("MONDAY").Attribute("ID").Value = "new value";
doc.Save("test.xml");
希望这有助于
Hope this helps
这篇关于如何在c#中生成自定义XML节点ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!