XNamespace ns = "http://schemas.devleap.com/Customer";
XDocument xmlCustomers = new XDocument(
new XElement(ns + "customers",
from c in customers
select new XElement(ns + "customer",
new XAttribute("city", c.City),
new XAttribute("name", c.Name),
new XAttribute("country", c.Country))));
xmlCustomers.Save(Console.Out);
Console.WriteLine();

XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add(XmlSchema.Read(new StreamReader(@"..\..\customer.xsd"), null));

// pebrn udlosti Changed pro koenov element
xmlCustomers.Changed += (sender, e) => {
xmlCustomers.Validate(schemas, (source, args) => {
if (args.Exception != null)
throw new InvalidOperationException("Operace v XML, nekonzistentn s pipojenm schmatem.", args.Exception);
});
};

// Odstran atribut city z prvnho zkaznka.
// (pravu schma nepovoluje)
xmlCustomers.Element(ns + "customers")
.Elements(ns + "customer").First()
.SetAttributeValue("city", null);
}
