XElement customer = XElement.Load(@"..\..\customer.xml");

// pihlen k odbru udlosti probhajc zmny pomoc vrazu Lambda
customer.Changing += (sender, e) => {
Console.WriteLine("=> Dolo k udlosti probhajc zmny.");
Console.WriteLine("\tProbh zmna typu: {0}", e.ObjectChange);

XObject x = sender as XObject;
Console.WriteLine("\tProbh zmna uzlu typu: {0}", x.NodeType);

XElement element = sender as XElement;
if (element != null) {
	Console.WriteLine("\tAktuln hodnota: {0}", element.Value);
}

XAttribute attribute = sender as XAttribute;
if (attribute != null) {
	Console.WriteLine("\tAktuln hodnota: {0}", attribute.Value);
}
};

// pihlen k odbru udlosti probhl zmny pomoc vrazu Lambda
customer.Changed += (sender, e) => {
Console.WriteLine("=>Dolo k udlosti probhl zmny.");
Console.WriteLine("\tProbhla zmna typu: {0}", e.ObjectChange);

XObject x = sender as XObject;
Console.WriteLine("\tProbhla zmna uzlu typu: {0}", x.NodeType);

XElement element = sender as XElement;
if (element != null) {
	Console.WriteLine("\tAktuln hodnota: {0}", element.Value);
}

XAttribute attribute = sender as XAttribute;
if (attribute != null) {
	Console.WriteLine("\tAktuln hodnota: {0}", attribute.Value);
}
};

// Vyhledn prvn adresy zkaznka
XElement emailAddress = customer
.Descendants("address")
.First(a => a.Attribute("type").Value == "email");
// Zmna textovho obsahu uzlu XML
emailAddress.Value = "paolo@devleap.com";
// Zmna hodnoty atributu typu
emailAddress.Attribute("type").Value = "externalEmail";
