控制序列化元素的顺序 [英] Controlling the order of serialized elements

查看:90
本文介绍了控制序列化元素的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,好的......从我能找到的,我会失去运气。我也知道它不应该是重要的,但确实如此。我正在尝试向亚马逊发送一些XML,并且他们要求节点处于特定的

订单中。我应该发送以下

订单中的元素:AmazonOrderID,MerchantOrderID,StatusCode,然后是一个集合

的Item元素。


当我序列化我的对象时,XML在收集item元素之后放置StatusCode元素

。 AAAARRRGGH!我无法想象

如何在Item集合之前移动状态代码元素

如果不是,亚马逊就不接受Feed !


任何人都可以帮助我吗?


这里是我代码中元素的定义:

Public AmazonOrderID As String

Public MerchantOrderID As String

< XmlElement(" StatusCode")>公共属性StatusCode()为

StatusCode

获取

返回_StatusCode

结束获取

设置(ByVal值为StatusCode)

_StatusCode =价值

结束集

结束财产

<的XmlElement()> Public Item()as structOrderAckItem


Private _StatusCode As StatusCode

Okay, okay... from what I can find, I''m gonna be out of luck. I also
understand that it *shouldn''t* matter but it does. I''m trying to send
some XML to Amazon and they''re requiring the nodes to be in a specific
order. I am supposed to send the elements in the following
order:AmazonOrderID, MerchantOrderID, StatusCode and then a collection
of Item elements.

When I serialize my object, the XML is putting the StatusCode element
after the collection of item elements. AAAARRRGGH!!! I can''t figure
out how to move the status code element ahead of the Item collection
and Amazon won''t accept the feed if it''s not!

Can anyone out there help me?

Here''s the definition of the elements in my code:
Public AmazonOrderID As String
Public MerchantOrderID As String
<XmlElement("StatusCode")> Public Property StatusCode() As
StatusCode
Get
Return _StatusCode
End Get
Set(ByVal Value As StatusCode)
_StatusCode = Value
End Set
End Property
<XmlElement()> Public Item() As structOrderAckItem

Private _StatusCode As StatusCode

推荐答案

如果将StatusCode转换为会发生什么?不是属性?

我认为xml序列化按此顺序完成:

所有公共字段,按照它们的定义顺序

所有公共财产,按其定义的顺序


因此,如果您拥有所有字段或所有属性,那么元素

的顺序将出现在xml序列化就像在源代码中定义的那样。
代码。如果你有混合的字段和属性,那么xml

序列化的顺序与源代码中声明的顺序不同。


-Dino

" Mark C. Neustadt" <毫安********** @ gmail.com>在消息中写道

news:d2 ************************** @ posting.google.c om ...
if you convert the StatusCode to a field and not a property, what happens?
I think xml serialization is done in this order:
all public fields, in the order they are defined
all public properties, in the order they are defined

So if you have all fields or all properties, then the order the elements
appear in xml serialization is just as they have been defined in source
code. If you have a mix of fields and properties, then the order for xml
serialization is different than the order as declared in source code.

-Dino
"Mark C. Neustadt" <ma**********@gmail.com> wrote in message
news:d2**************************@posting.google.c om...
好的,好的......从我能找到的,我会失去运气。我也明白它不应该是问题,但确实如此。我正在尝试向亚马逊发送一些XML,他们要求节点按照特定的顺序。我应该按以下顺序发送元素:AmazonOrderID,MerchantOrderID,StatusCode,然后是Item元素的集合。

当我序列化我的对象时,XML是在收集项目元素之后放置StatusCode元素。 AAAARRRGGH!我无法想象如何在Item集合之前移动状态代码元素
如果不是,亚马逊就不会接受它!
有人可以帮助我吗?

这里是我的代码中元素的定义:
公共AmazonOrderID As String
Public MerchantOrderID As String
< ;的XmlElement(QUOT;&的StatusCode QUOT)>公共属性StatusCode()为
StatusCode
获取
返回_StatusCode
结束获取
设置(ByVal值为StatusCode)
_StatusCode = Value
结束集
结束属性
< XmlElement()> Public Item()as structOrderAckItem
私有_StatusCode作为StatusCode
Okay, okay... from what I can find, I''m gonna be out of luck. I also
understand that it *shouldn''t* matter but it does. I''m trying to send
some XML to Amazon and they''re requiring the nodes to be in a specific
order. I am supposed to send the elements in the following
order:AmazonOrderID, MerchantOrderID, StatusCode and then a collection
of Item elements.

When I serialize my object, the XML is putting the StatusCode element
after the collection of item elements. AAAARRRGGH!!! I can''t figure
out how to move the status code element ahead of the Item collection
and Amazon won''t accept the feed if it''s not!

Can anyone out there help me?

Here''s the definition of the elements in my code:
Public AmazonOrderID As String
Public MerchantOrderID As String
<XmlElement("StatusCode")> Public Property StatusCode() As
StatusCode
Get
Return _StatusCode
End Get
Set(ByVal Value As StatusCode)
_StatusCode = Value
End Set
End Property
<XmlElement()> Public Item() As structOrderAckItem

Private _StatusCode As StatusCode



如果你将StatusCode转换为字段而不是属性,会发生什么?

我认为xml序列化按此顺序完成:

所有公共字段,按照它们的顺序定义

所有公共属性,按照它们的定义顺序


因此,如果你有所有字段或所有属性,那么元素

出现在xml序列化中的顺序就像它们一样已在源代码中定义

代码。如果你有混合的字段和属性,那么xml

序列化的顺序与源代码中声明的顺序不同。


-Dino

" Mark C. Neustadt" <毫安********** @ gmail.com>在消息中写道

news:d2 ************************** @ posting.google.c om ...
if you convert the StatusCode to a field and not a property, what happens?
I think xml serialization is done in this order:
all public fields, in the order they are defined
all public properties, in the order they are defined

So if you have all fields or all properties, then the order the elements
appear in xml serialization is just as they have been defined in source
code. If you have a mix of fields and properties, then the order for xml
serialization is different than the order as declared in source code.

-Dino
"Mark C. Neustadt" <ma**********@gmail.com> wrote in message
news:d2**************************@posting.google.c om...
好的,好的......从我能找到的,我会失去运气。我也明白它不应该是问题,但确实如此。我正在尝试向亚马逊发送一些XML,他们要求节点按照特定的顺序。我应该按以下顺序发送元素:AmazonOrderID,MerchantOrderID,StatusCode,然后是Item元素的集合。

当我序列化我的对象时,XML是在收集项目元素之后放置StatusCode元素。 AAAARRRGGH!我无法想象如何在Item集合之前移动状态代码元素
如果不是,亚马逊就不会接受它!
有人可以帮助我吗?

这里是我的代码中元素的定义:
公共AmazonOrderID As String
Public MerchantOrderID As String
< ;的XmlElement(QUOT;&的StatusCode QUOT)>公共属性StatusCode()为
StatusCode
获取
返回_StatusCode
结束获取
设置(ByVal值为StatusCode)
_StatusCode = Value
结束集
结束属性
< XmlElement()> Public Item()as structOrderAckItem
私有_StatusCode作为StatusCode
Okay, okay... from what I can find, I''m gonna be out of luck. I also
understand that it *shouldn''t* matter but it does. I''m trying to send
some XML to Amazon and they''re requiring the nodes to be in a specific
order. I am supposed to send the elements in the following
order:AmazonOrderID, MerchantOrderID, StatusCode and then a collection
of Item elements.

When I serialize my object, the XML is putting the StatusCode element
after the collection of item elements. AAAARRRGGH!!! I can''t figure
out how to move the status code element ahead of the Item collection
and Amazon won''t accept the feed if it''s not!

Can anyone out there help me?

Here''s the definition of the elements in my code:
Public AmazonOrderID As String
Public MerchantOrderID As String
<XmlElement("StatusCode")> Public Property StatusCode() As
StatusCode
Get
Return _StatusCode
End Get
Set(ByVal Value As StatusCode)
_StatusCode = Value
End Set
End Property
<XmlElement()> Public Item() As structOrderAckItem

Private _StatusCode As StatusCode



BINGO BABY!谢谢10 ^ 6 !!


我最初将设置为属性的东西,以便我可以使用

枚举来获取我的方式的价值需要它。我发现通过

将其更改为已定义的类型,然后将< XMLEnum()>在

枚举值之前,它完美无缺。


我希望这个小代码片段可以帮助人们。与亚马逊合作

非常困难。我的代码现在看起来像这样:


< Serializable(),XmlRoot(" OrderAcknowledgement")> _

公共类订单确认

公共AmazonOrderID为字符串

Public MerchantOrderID为字符串

Public StatusCode As StatusCodes

< XmlElement()> Public Item()as structOrderAckItem

End Class


Public Enum StatusCodes As Integer

< XmlEnum()>成功= 0

< XmlEnum()>失败

结束枚举


公共结构structOrderAckItem

Public AmazonOrderItemCode As String

Public MerchantOrderItemID As String

结束结构

------------------------------

Mark C. Neustadt,MCSD

Full Compass Systems,LTD。
00 ************** @ gmail.com _000

(删除前四个和后四个字符电子邮件地址)

***通过Devdex发送 http:// www.devdex.com ***

不要只是参加USENET ......获得奖励!
BINGO BABY! Thanks 10^6!!

I initially had the thing setup as a property so that I could use an
enumeration to get the value out the way I needed it. I found that by
changing it to a defined type and then putting <XMLEnum()> before the
enumerated values, it works perfectly.

I hope this little code snippet helps people out. Working with Amazon
has been very difficult. My code now looks like this:

<Serializable(), XmlRoot("OrderAcknowledgement")> _
Public Class OrderAcknowledgement
Public AmazonOrderID As String
Public MerchantOrderID As String
Public StatusCode As StatusCodes
<XmlElement()> Public Item() As structOrderAckItem
End Class

Public Enum StatusCodes As Integer
<XmlEnum()> Success = 0
<XmlEnum()> Failure
End Enum

Public Structure structOrderAckItem
Public AmazonOrderItemCode As String
Public MerchantOrderItemID As String
End Structure
------------------------------
Mark C. Neustadt, MCSD
Full Compass Systems, LTD.
00**************@gmail.com_000
(remove the first four and last four characters from the e-mail address)
*** Sent via Devdex http://www.devdex.com ***
Don''t just participate in USENET...get rewarded for it!


这篇关于控制序列化元素的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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