[英]How to convert List<string> to xml
我需要將String的List轉換為XML格式,我使用下面的代碼將List轉換為XML
XElement xmlElements = new XElement("DocumentElement", _UserIDs.Select(i => new XElement("BadgeNo", i)));
目前的結果:
<DocumentElement>
<BadgeNo>IMS001</BadgeNo>
<BadgeNo>IMS002</BadgeNo>
<BadgeNo>IMS003</BadgeNo>
<BadgeNo>IMS022</BadgeNo>
<BadgeNo>WAN35166</BadgeNo>
</DocumentElement>
但我需要更多東西,我需要像這樣添加一個額外的節點。 如何實現以下輸出
預期結果:
<DocumentElement>
<GroupInput>
<BadgeNo>IMS001</BadgeNo>
</GroupInput>
<GroupInput>
<BadgeNo>IMS002</BadgeNo>
</GroupInput>
<GroupInput>
<BadgeNo>IMS003</BadgeNo>
</GroupInput>
<GroupInput>
<BadgeNo>IMS022</BadgeNo>
</GroupInput>
<GroupInput>
<BadgeNo>WAN35166</BadgeNo>
</GroupInput>
</DocumentElement>
在此先感謝您的幫助。
在傳遞新的“BadgeNo”元素作為參數時選擇新的“GroupInput”元素:
XElement xmlElements = new XElement("DocumentElement",
_UserIDs.Select(i =>
new XElement("GroupInput",
new XElement("BadgeNo", i))
)
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.