我的 XML 文件如下:
<states>
<state name ="Alaska">
<Location Name="loc1">
<Address>testadd1</Address>
<DateNTime>d1</DateNTime>
</Location>
<Location Name="loc2">
<Address>add2</Address>
<DateNTime>d2</DateNTime>
</Location>
</state>
</states>
我已将其转换为以下字典,如下所示:
XDocument doc = XDocument.Load(Server.MapPath("test2.xml"));
IDictionary<string, Dictionary<string, Property>> dictionary = doc.Root.Elements("state").ToDictionary(
s => s.Attribute("name").Value,
s => s.Elements("Location").ToDictionary(
loc => loc.Attribute("Name").Value,
loc => new Property
{
address = loc.Element("Address").Value,
datetime = loc.Element("DateNTime").Value
}));
班级 :
public class Property
{
public string address;
public string datetime;
}
我已经对我的字典进行了更改,现在我需要将其转换回 XML 。谁能建议我怎么做?