控制XML名称空间的顺序 [英] Controlling the order of XML namepaces

查看:54
本文介绍了控制XML名称空间的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使"xmlns"首先出现在根属性列表中时遇到问题.

I'm having a problem getting the "xmlns" to appear first in the root attribute list.

我明白了:

  <myroot 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://www.someurl.com/ns/myroot http://www.someurl.com/xml/schemas/myschema.xsd"
        xmlns="http://www.someurl.com/ns/myroot"> 

       <sometag>somecontent</sometag>

    </myroot>

我想要这个:

<myroot 
        xmlns="http://www.someurl.com/ns/myroot" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://www.someurl.com/ns/myroot http://www.someurl.com/xml/schemas/myschema.xsd">

       <sometag>somecontent</sometag>

    </myroot>

我的代码如下:

  XNamespace rt = "http://www.someurl.com/ns/myroot";
        XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";

        var submissionNode = new XElement(XmlNameSpaces.rt + "myroot");
        submissionNode.Add(new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"));
        submissionNode.Add(new XAttribute(xsi + "schemaLocation", @"http://www.someurl.com/ns/myroot http://www.someurl.com/xml/schemas/myschema.xsd"););

我需要做些什么来改变订单?

What do i need to do different to change the order?

我了解订单通常不会被搁置,但在这种情况下是必需的.

I understand the order is not normally relavent, but its a requirement in this case.

推荐答案

XmlWriter 是否适合您?

Afaik,它使您可以完全控制属性和名称空间声明的顺序.

Afaik, it gives you full control of the order of attributes and namespace declarations.

这篇关于控制XML名称空间的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆