The prefix ” cannot be redefined from ” to within the same start element tag
You need to indicate that the element Foo is part of the namespace http://schemas.foo.com. Try this: XNamespace xNamespace = “http://schemas.foo.com”; XNamespace xsi = “http://www.w3.org/2001/XMLSchema-instance”; XElement foo = new XElement( xNamespace + “Foo”, new XAttribute(“xmlns”, “http://schemas.foo.com”), new XAttribute(XNamespace.Xmlns + “xsi”, “http://www.w3.org/2001/XMLSchema-instance”), new XAttribute(xsi + “schemaLocation”, “http://schemas.foo.com http://schemas.foo.com/Current/xsd/Foo.xsd”) );