C# XML名称空间顺序XML序列化
下面是为创建XML而添加的名称空间C# XML名称空间顺序XML序列化,c#,xml,visual-studio-2008,xml-namespaces,C#,Xml,Visual Studio 2008,Xml Namespaces,下面是为创建XML而添加的名称空间 XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("xsd", "http://www.w3.org/2001/XMLSchema"); ns.Add("versione", "FPA12"); ns.Add("xsi", "http://www.w3.org
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("xsd", "http://www.w3.org/2001/XMLSchema");
ns.Add("versione", "FPA12");
ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
期望输出
<FatturaElettronica xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" versione="FPA12" xmlns="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2">
生成输出
<FatturaElettronica xmlns:versione="FPA12" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2">
是否有方法更改名称空间的顺序,以及在生成的输出中,您可以看到xmlns:versione=“FPA12”但客户端只需要
versione=“FPA12”奇怪的是,属性的顺序对xml元素有什么影响?是的。但是客户机希望它处于相同的顺序,即使在解释了它之后也不要紧。如果您只希望
versione=“FPA12”
这是一个普通属性,而不是名称空间声明,因此,您不会通过XmlSerializerNamespaces
添加它。我从未遇到过一个XML序列化程序,它可以让您控制命名空间声明的顺序。你不应该在意的。你似乎处于一个典型的位置,客户不理解他们的要求。我遇到了一个重要的场景:版本控制。与XML语义无关,但如果仅仅因为objectGetHashCode
在拉动字符串,文件差异就会毫无理由地出现,这会让人恼火。