我想要下面的Xml格式使用Xml serilization使用Vb.net,请任何人帮助我 [英] I want the below Xml format Using Xml serilization Using Vb.net, Please any one help me

查看:55
本文介绍了我想要下面的Xml格式使用Xml serilization使用Vb.net,请任何人帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<SubSiteCUInput xmlns="SummitEnergy.ExternalAPI.SubSiteCUAPI.SubSiteCUInput" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <Sites xmlns:a="SummitEnergy.ExternalAPI.SubSiteCUAPI.Site">
    <a:Site>
      <a:SiteId>261289</a:SiteId>
      <a:SubSites xmlns:b="SummitEnergy.ExternalAPI.SubSiteCUAPI.SubSite">
        <b:SubSite>
          <b:Services xmlns:c="SummitEnergy.ExternalAPI.SubSiteCUAPI.Service">
            <c:Service>
              <c:CostUsageData xmlns:d="SummitEnergy.ExternalAPI.SubSiteCUAPI.CostUsageData">
                <d:CostUsageData>
                  <d:Cost/>
                  <d:CurrencyUOM/>
                  <d:ServiceMonth>03/2011</d:ServiceMonth>
                  <d:Usage/>
                  <d:UsageUOM>12</d:UsageUOM>
                </d:CostUsageData>
              </c:CostUsageData>
              <c:ServiceId>290</c:ServiceId>
            </c:Service>
          </b:Services>
          <b:SubSiteId>2708</b:SubSiteId>
        </b:SubSite>
      </a:SubSites>
    </a:Site>
  </Sites>
</SubSiteCUInput>

推荐答案

好吧,如果你需要那种风格,你可以编写自己的基于XML的序列化器。但首先,尝试.NET FCL中可用的最佳序列化程序: System.Runtime.Serialization.DataContractSerializer

http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer。 aspx [ ^ ]。



它产生的东西非常相似,并且基于最佳的序列化方法 - 数据合同。请参阅:

http://msdn.microsoft.com/en-us /library/ms733127.aspx [ ^ ]。



如果您仍然需要稍微不同的格式,那么您可能需要自己的序列化程序。如果你想自己实现数据契约,这是不可知 对象图的特定数据类型,这很可能,但很难。这样做相对容易,你的文件不是很大,因为反射很慢。快速序列化也很有可能,但它要困难得多,因为它还需要 System.Reflection.Emit ,它可以帮助你避免反复重复反射,但它需要熟悉IL并且难以调试。



-SA
Well, if you need exactly that style, you can write your own XML based serializer. But first of all, try the best serializer available in .NET FCL: System.Runtime.Serialization.DataContractSerializer:
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx[^].

It produces something very similar and is based on the best approach to serialization, Data Contract. Please see:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

If you still need slightly different format, chances are, you would need your own serializer. If you want to make your own implementation of Data Contract, which is agnostic to the particular data types of the object graphs, this is quite possible, but difficult enough. It's relatively easy to do it your files are not very big, because reflection is slow. Fast serialization is also quite possible, but it's much more difficult as it would require also System.Reflection.Emit, which can help you to avoid repeating reflection over and over, but it requires good knowledge of IL and hard for debugging.

—SA


这篇关于我想要下面的Xml格式使用Xml serilization使用Vb.net,请任何人帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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