假設我有一個XML文件作爲下如何使用XDocument刪除數據?
<DataBaseServers>
<DataBaseServer id="1" title="IISDevdb1" address="Address1">
<DataBases>
<database id="1" name="db1" userID="u1" password="p1" />
<database id="3" name="db3" userID="u3" password="p3" />
</DataBases>
</DataBaseServer>
<DataBaseServer id="2" title="iis2" address="Address2">
<DataBases>
<database id="2" name="db2" userID="u2" password="p2" />
</DataBases>
</DataBaseServer>
</DataBaseServers>
我想刪除數據庫ID = 「3」。
生成的XML將
<DataBaseServers>
<DataBaseServer id="1" title="IISDevdb1" address="Address1">
<DataBases>
<database id="1" name="db1" userID="u1" password="p1" />
</DataBases>
</DataBaseServer>
<DataBaseServer id="2" title="iis2" address="Address2">
<DataBases>
<database id="2" name="db2" userID="u2" password="p2" />
</DataBases>
</DataBaseServer>
</DataBaseServers>
如果我刪除數據庫ID = 「2」,XML將看起來
<DataBaseServers>
<DataBaseServer id="1" title="IISDevdb1" address="Address1">
<DataBases>
<database id="1" name="db1" userID="u1" password="p1" />
<database id="3" name="db3" userID="u3" password="p3" />
</DataBases>
</DataBaseServer>
<DataBaseServer id="2" title="iis2" address="Address2"/>
</DataBaseServers>
它使用的XDocument我該怎麼辦?
我想刪除數據庫id =「3」。那我該怎麼辦? –
您的代碼是否會(現在)刪除整個文檔? – Tim
實際上它只用於演示,現在我更新了代碼,檢查它 –