从序列化对象中删除子元素上的名称空间 [英] Removing namespaces on child elements from serialised object

查看:75
本文介绍了从序列化对象中删除子元素上的名称空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在序列化一个集合类型和属性,这些属性已被序列化为子元素,并且每个子元素都有默认的命名空间( http://tempuri.org/ )。现在我知道这些已经从已经序列化的对象中下来了,但是在那里我可以在序列化过程中删除这些命名空间(或者替换它们)?

我得到的XML输出是遵循...


< SearchCompany> 
< Company_ID xmlns =" http://tempuri.org/"> 98838401< / Company_ID>
< CompanyName xmlns =" http://tempuri.org/"> 3X Bankprojekt GmbH< / CompanyName>
< CompanyNumber xmlns =" http://tempuri.org/"> 510620< / CompanyNumber>
< CompanyStatus xmlns =" http://tempuri.org/"> active< / CompanyStatus>
< Street xmlns =" http://tempuri.org/"> St.-Martinus-Str。 3'; /街道>
< City xmlns =" http://tempuri.org/"> Ellwangen< / City>
< Postalcode xmlns =" http://tempuri.org/"> 73479< / Postalcode>
< LastAccountsDate xmlns =" http://tempuri.org/"> 0< / LastAccountsDate>
< CreditScore xmlns =" http://tempuri.org/"> 0< / CreditScore>
< / SearchCompany>


提前致谢。

试试


试试

解决方案



你可以尝试这样的事情

XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns。添加(","");
ser.Serialize(Console.Out,ts,ns);

ser - XmlSerializer
ts - 我的对象

Hi all,

I am serialising a collection types and on the attributes, which have been serialised as child elements, and each of these child elements has the default namespace on them (http://tempuri.org/ ). Now I know these has come down from the object that has been serialised, but is there anyway I can remove these namespaces (or replace then) during the serialisation process?

The XML output I am getting is as follows...

<SearchCompany>
  <Company_ID xmlns="http://tempuri.org/">98838401</Company_ID> 
  <CompanyName xmlns="http://tempuri.org/">3X Bankprojekt GmbH</CompanyName> 
  <CompanyNumber xmlns="http://tempuri.org/">510620</CompanyNumber> 
  <CompanyStatus xmlns="http://tempuri.org/">active</CompanyStatus> 
  <Street xmlns="http://tempuri.org/">St.-Martinus-Str. 3</Street> 
  <City xmlns="http://tempuri.org/">Ellwangen</City> 
  <Postalcode xmlns="http://tempuri.org/">73479</Postalcode> 
  <LastAccountsDate xmlns="http://tempuri.org/">0</LastAccountsDate> 
  <CreditScore xmlns="http://tempuri.org/">0</CreditScore> 
  </SearchCompany>

Thanks in advance.

Tryst


Tryst

解决方案

Hi,

You can try something like this

 XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
            ns.Add("", "");
            ser.Serialize(Console.Out, ts,ns);

ser - XmlSerializer
ts - My object


这篇关于从序列化对象中删除子元素上的名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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