我想同时使用的XmlSerializer得到以下XML:序列化根元素的命名空间,没有命名空间
<?xml version="1.0"?>
<GetProfileRequest xmlns="urn:veloconnect:profile-1.1">
</GetProfileRequest>
但是,当我序列化,我得到以下XML:
<?xml version="1.0"?>
<GetProfileRequest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
</GetProfileRequest>
序列化代码:
GetProfileRequest request = new GetProfileRequest();
XmlSerializer serialize = new XmlSerializer(typeof(GetProfileRequest));
serialize.Serialize(Response.OutputStream, request);
类:
[System.Xml.Serialization.XmlIncludeAttribute(typeof(TransactionRequestType))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "urn:veloconnect:profile-1.1")]
public partial class GetProfileRequest : RequestType
{
}
[System.Xml.Serialization.XmlIncludeAttribute(typeof(TransactionRequestType))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:veloconnect:transaction-1.0")]
public partial class RequestType
{
}
是否有一个属性可以在类“GetProfileRequest”中定义,或者有助于将xmlns =“urn:veloconnect:profile-1.1”命名空间放入XML中?
我还尝试通过以下代码手动添加XmlSerializeNamespace,但这只是删除了根元素中的所有名称空间声明,而不是创建所需的声明。
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "urn:veloconnect:profile-1.1");
// and then call serialize.Serialize with ns
这正是我正在寻找的。非常感谢! – Undercover1989 2015-03-13 16:34:14