2012-09-11 80 views
0

我輸入就像是一個字符串:<Identification LastName="Bornery" Name="John" Age="23"/>,我想將它轉換爲XML,然後改變它想:<Identification LastName="Bornery" Name="John" Age="40"/>更換新的屬性值

+0

在某些情況下,我必須使用源自Xml格式的字符串,我必須嘗試將這兩種格式轉換爲對方,並對它們進行一些更改。 – SMD

回答

1

這應該做的,但很多其他方面也。什麼是最適合你的需要更多信息。

var xd = XDocument.Parse(@"<Identification LastName=""Bornery"" Name=""John"" Age=""23""/>"); 
xd.Element("Identification").Attribute("Age").Value = "40"; 
string result = xd.ToString(); 
+0

非常感謝。 – SMD