【发布时间】:2019-08-19 07:51:32
【问题描述】:
我在 .xml 文件中有代码,我想将 .xml 文件中的属性值分配给字段。
.csharp
private static string camera_model_c1_set = xml_read_set_cip_c1.Descendants("root").ElementAt("camera_model_c1_set").Att
.csharp
Parameter name: value '
XDocument name_of_file_xml = new XDocument(
new XComment("document"),
new XElement("root",
new XElement("name", new XAttribute ("name2", myvalue ))
)
);
.xml
<?xml version="1.0" encoding="utf-8"?>
<!--document-->
<root>
<name name2="myvalue" />
</root>
我想将这个“myvalue”转换为 .cs 代码:
static string new_my_var = ... (?)
我有
XDocument xml_doc = XDocument.Load(path);
我关心在这段代码中使用XDocument。 (而不是XmlDocument)
【问题讨论】:
-
欢迎来到 Stack Overflow。 “其实我没有结果。” - 你到底是什么意思?您当前的代码返回什么?老实说,我不希望它编译......如果你能提供一个明确的minimal reproducible example,这将有所帮助。目前你有代码来创建一个
XDocument,但如果你已经得到了文件,你可能不需要它......但我们需要你的实际 读取文档的代码以及结果。