XML属性顺序

时间:2018-04-27 17:34:22

标签: c#

我有这个用于编写XML的代码

        XmlWriterSettings settings = new XmlWriterSettings();
        settings.Indent = true;
        settings.IndentChars = ("\t");

        XmlWriter writer = XmlWriter.Create("sample.xml",settings);
        writer.WriteStartDocument();
        writer.WriteStartElement("Report", "http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition");
        writer.WriteAttributeString("xmlns","rd", null, "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner");
        writer.WriteEndElement();
        writer.WriteEndDocument();

        writer.Close();

上面的代码在我的 sample.xml 中产生了这个输出:

<?xml version="1.0" encoding="utf-8"?>
<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition" />

然而,我想要的是输出:

<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">

我尝试重新订购我的代码,但似乎没有用。

0 个答案:

没有答案