xml - 如何将每个键的多个值写入 XML 文件?
问题描述
我有一个简单的 XML 文件:
<?xml version="1.0" encoding="utf-16"?>
<dictionary>
<Item>
<Key>
<string>Stations</string>
</Key>
<Value>
<string>Station 1</string>
</Value>
</Item>
<Item>
<Key>
<string>Vendors</string>
</Key>
<Value>
<string>Vendor 1</string>
</Value>
</Item>
</dictionary>
所以我想为每个键保存多个值。在此示例中,我将添加供应商 2 或类似的东西。我需要能够存储多个站点、多个供应商,但我不知道如何在 XML 中执行此操作。我在我的 C# 应用程序中使用它来读取不时更改的数据,因此我无法对其进行硬编码。我只是希望每个键都能拥有一个“列表”。这可能吗?
解决方案
你可以有一个像这样的 XML:
<?xml version="1.0" encoding="utf-16"?>
<dictionary>
<Item>
<Key>
<string>Stations</string>
</Key>
<Value>
<string>Station 1</string>
<string>Station 2</string>
</Value>
</Item>
<Item>
<Key>
<string>Vendors</string>
</Key>
<Value>
<string>Vendor 1</string>
<string>Vendor 2</string>
<string>Vendor 3</string>
</Value>
</Item>
</dictionary>
推荐阅读
- python - 如何提高下面代码的速度以在列的每个单元格中进行更改
- excel - 计算 Excel 中具有相同票证的唯一名称的数量#
- flutter - flutter_bloc 中的 easy_localization 问题
- chisel - SyncReadMem 生成的 verilog 与 Rocketchip 发出的 verilog
- javascript - React 条件渲染 - 加载组件
- swiftui - SwiftUI NavigationLink 在删除然后插入新的 ForEach 元素后中断
- java - 如何通过使用弹簧功能扫描所有类来检测和处理自定义注释
- python - 将页眉和页脚添加到 txt 文档?并将其复制到另一个txt。格式
- php - 使用 Laravel 7 和 Maatwebsite 导出具有多个表的 Excel
- mysql - 使用have子句根据mysql别名获取记录