我想按照我的要求插入迭代元素(信號),如下面的xml輸出。如何使用C#.net在XMl文件中插入迭代元素?
<?xml version="1.0" encoding="UTF-8"?>
<WIUConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Timestamp>2006-05-04T18:13:51.0Z</Timestamp>
<WIUAddress>WIUAddress0</WIUAddress>
<WIUName>WIUName0</WIUName>
<BeaconFlag>Y</BeaconFlag>
<EncryptedHMACkey>30</EncryptedHMACkey>
<DeviceStatusConfigVersion>DeviceStatusConfigVersion0</DeviceStatusConfigVersion>
<Signal>
<SiteDeviceId>SiteDeviceId0</SiteDeviceId>
<SiteName>SiteName0</SiteName>
<TrackName>TrackName0</TrackName>
</Signal>
<Signal>
<SiteDeviceId>SiteDeviceId1</SiteDeviceId>
<SiteName>SiteName1</SiteName>
<TrackName>TrackName1</TrackName>
</Signal>
<Signal>
.
.
.
</Signal>
</WIUConfig>
我怎麼可以使用C#.NET的LINQ to XML
這裏實現這一目標迭代的概念是我的代碼:
XDocument xdco = new XDocument(
new XDeclaration("1.0", "utf-8", "Yes"),
new XComment("WIU Configurations"),
new XElement("WIUConfig",
new XElement("Timestamp", datetime),
new XElement("WIUAddress", ds.Tables[0].Rows[0][0].ToString()),
new XElement("WIUName", ds.Tables[0].Rows[0][1].ToString()),
new XElement("BeaconFlag", "Y"),
new XElement("EncryptedHMACkey", ds1.Tables[0].Rows[0][0].ToString()),
new XElement("DeviceStatusConfigSCAC", ds.Tables[0].Rows[0][0].ToString()),
new XElement("DeviceStatusConfigTableId", ds.Tables[0].Rows[0][0].ToString()),
new XElement("DeviceStatusConfigVersion", ds.Tables[0].Rows[0][0].ToString()),
**????????(iteration code) **
));
xdco.Save(OutPath);
從上面的代碼如何插入與XML文件迭代元素?
你的信號在某種集合中? (新的XElement(「Signal」,new XElement(「SiteDeviceId」))使用以下代碼解析的: – 2010-11-19 08:28:53
:for(int i = 0; i
Jeyavel
2010-11-19 08:36:06