简体   繁体   English

使用 DataContractSerializer 时删除 xmlns:i="http://www.w3.org/2001/XMLSchema-instance"

[英]remove xmlns:i=“http://www.w3.org/2001/XMLSchema-instance” when using DataContractSerializer

how can I remove the xmlns:i="http://www.w3.org/2001/XMLSchema-instance" when using DataContractSerializer.使用 DataContractSerializer 时如何删除 xmlns:i="http://www.w3.org/2001/XMLSchema-instance"。

this is what I'm getting:这就是我得到的:

<ProfileModel xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <Email>wolverine@wolverine.com</Email>
  <FirstName>wolverine</FirstName>
  <ID>ty1002225</ID>
  <LastName>wolverine3</LastName>
  <PhoneNumber>66332214477</PhoneNumber>
  <SourceSystem>TY</SourceSystem>
</ProfileModel>

I want to get something like this:我想得到这样的东西:

<ProfileModel>
      <Email>wolverine@wolverine.com</Email>
      <FirstName>wolverine</FirstName>
      <ID>ty1002225</ID>
      <LastName>wolverine3</LastName>
      <PhoneNumber>66332214477</PhoneNumber>
      <SourceSystem>TY</SourceSystem>
    </ProfileModel>

this is my model:这是我的模型:

[DataContract(Namespace = "")]
    public class CRMProfileModel
    {
        [DataMember]
        public string FirstName { get; set; }
        [DataMember]
        public string LastName { get; set; }
        [DataMember]
        public string Email { get; set; }
        [DataMember]
        public string PhoneNumber { get; set; }
        [DataMember]
        public string SourceSystem { get; set; }
        [DataMember]
        public string ID { get; set; }
    }

I'm trying to avoid to use string replace to remove it.我试图避免使用字符串替换来删除它。

how can I remove the xmlns:i="http://www.w3.org/2001/XMLSchema-instance" when using DataContractSerializer.使用 DataContractSerializer 时如何删除 xmlns:i="http://www.w3.org/2001/XMLSchema-instance"。

  1. hii Romeo ... i also tried for couple of hours to remove xmlns:i="http://www.w3.org/2001/XMLSchema-instance".你好罗密欧...我也尝试了几个小时来删除 xmlns:i="http://www.w3.org/2001/XMLSchema-instance"。

  2. Finally i found my best,hope it will helpful最后我找到了我最好的,希望它会有所帮助

    public IHttpActionResult Post([FromBody]MessageResponse value) public IHttpActionResult Post([FromBody]MessageResponse 值)

{ {

 var messageresponse =new CRMProfileModel(){.....};
DataContractSerializer doc = new  DataContractSerializer(messageresponse.GetType());  
MemoryStream ms = new MemoryStream();
 dcs.WriteObject(ms, messageresponse); 
var i = Encoding.UTF8.GetString(ms.ToArray()); 
var r = i.Replace("xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"","");
var ss = new XmlDocument(); 
ss.LoadXml(r);
return Content(HttpStatusCode.OK, ss.DocumentElement, Configuration.Formatters.XmlFormatter);

} }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 避免在.Net DataContractSerializer中使用“http://www.w3.org/2001/XMLSchema-instance”命名空间 - Avoiding using the “http://www.w3.org/2001/XMLSchema-instance” namespace with .Net DataContractSerializer 删除 p2:type="&lt;<type> &gt;" xmlns:p2="http://www.w3.org/2001/XMLSchema-instance" 来自 xml</type> - Remove p2:type="<<type>>" xmlns:p2="http://www.w3.org/2001/XMLSchema-instance" from xml 从名称空间&#39;http://www.w3.org/2001/XMLSchema-instance&#39;期望元素&#39;CustomerLeads&#39; - Expecting element 'CustomerLeads' from namespace 'http://www.w3.org/2001/XMLSchema-instance' C#中的XML反序列化错误-InvalidOperationException: <element xmlns='http://www.w3.org/2001/XMLSchema'> 没想到 - XML Deserialization Error in C# - InvalidOperationException: <element xmlns='http://www.w3.org/2001/XMLSchema'> was not expected 具有“ http://www.w3.org/2001/XMLSchema”名称空间的性能影响 - Performance impact of having “http://www.w3.org/2001/XMLSchema” namespace 元素http://www.w3.org/2001/XMLSchema:complexType在此上下文中无效 - Element http://www.w3.org/2001/XMLSchema:complexType is invalid in this context C# XPathSelectElement 和 xml 属性 xmlns=“http://www.w3.org/2000/09/xmldsig#” 帮助 - C# XPathSelectElement and xml with attribute xmlns=“http://www.w3.org/2000/09/xmldsig#” Help JWT Header 算法:“hs256”与“http://www.w3.org/2001/04/xmldsig-more#hmac-sha256”相同 - JWT Header algorithm: is "hs256" the same as "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256" DNX Core 5.0 JwtSecurityTokenHandler“ IDX10640:不支持算法:&#39;http://www.w3.org/2001/04/xmldsig-more#hmac-sha256&#39;” - DNX Core 5.0 JwtSecurityTokenHandler “IDX10640: Algorithm is not supported: 'http://www.w3.org/2001/04/xmldsig-more#hmac-sha256'” SignedXml CanonicalizationMethod - http://www.w3.org/2006/12/xml-c14n11 - SignedXml CanonicalizationMethod - http://www.w3.org/2006/12/xml-c14n11
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM