我需要将以下属性添加到XElement中:
<xmlns="http://www.mysite.com/myresource" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mysite.com/myresource TheResource.xsd">
它花了
a lot of blogs,但我终于想出了我认为是这样做的“正确”方式:
XNamespace ns = @"http://www.myapp.com/resource"; XNamespace xsi = @"http://www.w3.org/2001/XMLSchema-instance"; var root = new XElement(ns + "root",new XAttribute(XNamespace.Xmlns+"xsi",xsi.NamespaceName),new XAttribute(xsi + "schemaLocation",@"http://www.myapp/resource TheResource.xsd") );