這樣我就可以獲得記錄的詳細信息,並且我想知道如何編輯這些值並將其更新爲相同的記錄?xml中的更新記錄
如何檢查屬性中的唯一值?
XDocument doc = XDocument.Load(filePath);
string id = textBox6.Text;
XElement element = doc.Descendants("Customer").FirstOrDefault(p => p.Attribute("id").Value == id);
if (element != null)
{
//found
textBox6.Text = textBox6.Text;
textBox1.Text = (string)element.Element("FirstName");
textBox2.Text = (string)element.Element("LastName");
textBox3.Text = (string)element.Element("Mobile");
textBox4.Text = (string)element.Element("Address");
textBox5.Text = (string)element.Element("Country");
}
示例XML:
<?xml version="1.0" encoding="utf-8"?>
<CustomerRecord>
<Customer id="43543543">
<FirstName>sdf</FirstName>
<LastName>fdsf</LastName>
<Mobile>23452345é</Mobile>
<Address>zfdsf</Address>
<Country>dsfdsf</Country>
</Customer>
</CustomerRecord>
:我如何更新身份證? – linguini 2012-08-11 21:32:09
剛剛更新了我的回答 – 2012-08-11 21:38:20
@Genial,Merci。 – linguini 2012-08-11 21:40:46