Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用LINQtoXML编写NAnt.build文件_Xml_Linq_Linq To Xml_Nant_Xml Namespaces - Fatal编程技术网

使用LINQtoXML编写NAnt.build文件

使用LINQtoXML编写NAnt.build文件,xml,linq,linq-to-xml,nant,xml-namespaces,Xml,Linq,Linq To Xml,Nant,Xml Namespaces,我正在尝试使用C#和Linq to XML创建一个XML文件,但是nant名称空间有问题 var myXElement = new XElement("project", new XAttribute("name", "MySystemName"), new XAttribute("default", "myNAntTargetName"), new XAttribute("xmlns", "http://nant.sf.net/schemas/nant.xsd")); myXElement.

我正在尝试使用C#和Linq to XML创建一个XML文件,但是nant名称空间有问题

var myXElement = new XElement("project", new XAttribute("name", "MySystemName"), new XAttribute("default", "myNAntTargetName"), new XAttribute("xmlns", "http://nant.sf.net/schemas/nant.xsd"));

myXElement.Save("c:\foo.xml");
因为我试图在命名空间中强制Xattribute(to)the.Save失败,原因是:

XmlException未处理:无法在同一开始元素标记中将前缀“”从“”重新定义为“”

如果我只是删除namespace属性,文件保存得很好,但是我需要在其中包含名称空间,否则我的NAnt命令会失败


有什么建议吗

在互联网上搜索了很长时间后发现:

基本上,我需要定义一个名称空间,并在代码中应用它(在任何地方),当文件被保存时,名称空间被省略

希望这对其他人有帮助!如果是这样,请投票给我好吗