XmlWriter格式化问题

时间:2016-02-23 21:37:25

标签: c# xml xmlwriter

您好我对XmlWriter的使用不太熟悉所以请耐心等待。我在下面有这段代码来格式化一段XML的StartElement

 var soapEnv = "http://schemas.xmlsoap.org/soap/envelope/";
 using (var sw = new StringWriter())
        {
            using (var writer = XmlWriter.Create(sw))
            {

                // Build Xml with xw.
                writer.WriteStartDocument();

                writer.WriteStartElement("soapenv", "Envelope", soapEnv);
                writer.WriteAttributeString("xmlns", "test", null, "testString");

此格式返回:  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:test="testString">

但是我想在StartElement中交换2个AttributeStrings,所以它看起来像这样:

<soapenv:Envelope xmlns:test="testString" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

我不确定如何解决这个问题。有人可以提出建议,我将不胜感激。

0 个答案:

没有答案