通常,所有这些都非常适合将我的对象序列化为 Xml 字符串并再次序列化为对象。但是,我似乎无法追踪不同最终用户之间的这种不一致。
基本上,当我序列化一个对象时,一旦转换为 Xml,它看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<Step xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Name>Step 2</Name>
<VoltageDip>20</VoltageDip>
<Loads>
<Load xsi:type="ThreePhaseMotorLoad">
<Name>Motor 450 KW Pump</Name>
<Comments />
<Quantity>1</Quantity>
<Voltage>
<Name>400 Volt 3 Phase 12w 50Hz</Name>
<V3Id xsi:nil="true" />
<Value>400</Value>
<V3Value>415</V3Value>
<Connection>Wye</Connection>
<Phase>3</Phase>
<RangeDescription>231/400v</RangeDescription>
<VoltageCode>F</VoltageCode>
<Active>true</Active>
<Frequency>50</Frequency>
<PowerFactor>0.8000</PowerFactor>
<UL2200>false</UL2200>
<Default>false</Default>
<TempRiseIds>
<TempRiseId>F</TempRiseId>
</TempRiseIds>
</Voltage>
<IsNonLinear>true</IsNonLinear>
<PriorityProperty>KWm</PriorityProperty>
<KW>0</KW>
<RunningPowerFactor xsi:nil="true" />
<StartingPowerFactor>0.90</StartingPowerFactor>
<KWm>450</KWm>
<Efficiency xsi:nil="true" />
<IsLowInertia>false</IsLowInertia>
<MotorStandard>NEMA</MotorStandard>
<MotorStartingMethod>VariableFrequencyDrive</MotorStartingMethod>
<NEMAMotorCode>F</NEMAMotorCode>
<SolidStateStarterPercent>0</SolidStateStarterPercent>
<LockedRotorKVAPerHP>5.3</LockedRotorKVAPerHP>
</Load>
<Load xsi:type="ThreePhaseMotorLoad">
<Name>Motor 450 KW Pump</Name>
<Comments />
<Quantity>1</Quantity>
<Voltage>
<Name>400 Volt 3 Phase 12w 50Hz</Name>
<V3Id xsi:nil="true" />
<Value>400</Value>
<V3Value>415</V3Value>
<Connection>Wye</Connection>
<Phase>3</Phase>
<RangeDescription>231/400v</RangeDescription>
<VoltageCode>F</VoltageCode>
<Active>true</Active>
<Frequency>50</Frequency>
<PowerFactor>0.8000</PowerFactor>
<UL2200>false</UL2200>
<Default>false</Default>
<TempRiseIds>
<TempRiseId>F</TempRiseId>
</TempRiseIds>
</Voltage>
<IsNonLinear>true</IsNonLinear>
<PriorityProperty>KWm</PriorityProperty>
<KW>0</KW>
<RunningPowerFactor xsi:nil="true" />
<StartingPowerFactor>0.90</StartingPowerFactor>
<KWm>450</KWm>
<Efficiency xsi:nil="true" />
<IsLowInertia>false</IsLowInertia>
<MotorStandard>NEMA</MotorStandard>
<MotorStartingMethod>VariableFrequencyDrive</MotorStartingMethod>
<NEMAMotorCode>F</NEMAMotorCode>
<SolidStateStarterPercent>0</SolidStateStarterPercent>
<LockedRotorKVAPerHP>5.3</LockedRotorKVAPerHP>
</Load>
<Load xsi:type="ThreePhaseMotorLoad">
<Name>Motor 450 KW Pump</Name>
<Comments />
<Quantity>1</Quantity>
<Voltage>
<Name>400 Volt 3 Phase 12w 50Hz</Name>
<V3Id xsi:nil="true" />
<Value>400</Value>
<V3Value>415</V3Value>
<Connection>Wye</Connection>
<Phase>3</Phase>
<RangeDescription>231/400v</RangeDescription>
<VoltageCode>F</VoltageCode>
<Active>true</Active>
<Frequency>50</Frequency>
<PowerFactor>0.8000</PowerFactor>
<UL2200>false</UL2200>
<Default>false</Default>
<TempRiseIds>
<TempRiseId>F</TempRiseId>
</TempRiseIds>
</Voltage>
<IsNonLinear>true</IsNonLinear>
<PriorityProperty>KWm</PriorityProperty>
<KW>0</KW>
<RunningPowerFactor xsi:nil="true" />
<StartingPowerFactor>0.90</StartingPowerFactor>
<KWm>450</KWm>
<Efficiency xsi:nil="true" />
<IsLowInertia>false</IsLowInertia>
<MotorStandard>NEMA</MotorStandard>
<MotorStartingMethod>VariableFrequencyDrive</MotorStartingMethod>
<NEMAMotorCode>F</NEMAMotorCode>
<SolidStateStarterPercent>0</SolidStateStarterPercent>
<LockedRotorKVAPerHP>5.3</LockedRotorKVAPerHP>
</Load>
</Loads>
</Step>
但是,当其他随机用户运行我的程序并序列化该对象时,他们最终会得到这样的结果:
<?xml version="1.0" encoding="utf-8"?>
<Step xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Name>Step 2</Name>
<Loads>
<Load xsi:type="ThreePhaseMotorLoad">
<Name>Motor 450 KW Pump</Name>
<Comments />
<Quantity>1</Quantity>
<Voltage>
<Name>240 Volt 3 Phase 12w 60Hz</Name>
<RangeDescription>120/240v</RangeDescription>
<V3Id>3</V3Id>
<Value>240</Value>
<V3Value>480</V3Value>
<Connection>Delta</Connection>
<Phase>3</Phase>
<VoltageCode>J</VoltageCode>
<Active>true</Active>
<Frequency>60</Frequency>
<PowerFactor>0.8000</PowerFactor>
<UL2200>true</UL2200>
<Default>true</Default>
<TempRiseIds>
<TempRiseId>B</TempRiseId>
<TempRiseId>C</TempRiseId>
<TempRiseId>D</TempRiseId>
<TempRiseId>E</TempRiseId>
</TempRiseIds>
</Voltage>
<IsNonLinear>true</IsNonLinear>
<PriorityProperty>KWm</PriorityProperty>
<KW>0</KW>
<RunningPowerFactor xsi:nil="true" />
<StartingPowerFactor>0.90</StartingPowerFactor>
<KWm>450</KWm>
<Efficiency xsi:nil="true" />
<IsLowInertia>false</IsLowInertia>
<MotorStandard>NEMA</MotorStandard>
<MotorStartingMethod>VariableFrequencyDrive</MotorStartingMethod>
<NEMAMotorCode>F</NEMAMotorCode>
<SolidStateStarterPercent>0</SolidStateStarterPercent>
<LockedRotorKVAPerHP>5.3</LockedRotorKVAPerHP>
</Load>
<Load xsi:type="ThreePhaseMotorLoad">
<Name>Motor 450 KW Pump</Name>
<Comments />
<Quantity>1</Quantity>
<Voltage>
<Name>240 Volt 3 Phase 12w 60Hz</Name>
<RangeDescription>120/240v</RangeDescription>
<V3Id>3</V3Id>
<Value>240</Value>
<V3Value>480</V3Value>
<Connection>Delta</Connection>
<Phase>3</Phase>
<VoltageCode>J</VoltageCode>
<Active>true</Active>
<Frequency>60</Frequency>
<PowerFactor>0.8000</PowerFactor>
<UL2200>true</UL2200>
<Default>true</Default>
<TempRiseIds>
<TempRiseId>B</TempRiseId>
<TempRiseId>C</TempRiseId>
<TempRiseId>D</TempRiseId>
<TempRiseId>E</TempRiseId>
</TempRiseIds>
</Voltage>
<IsNonLinear>true</IsNonLinear>
<PriorityProperty>KWm</PriorityProperty>
<KW>0</KW>
<RunningPowerFactor xsi:nil="true" />
<StartingPowerFactor>0.90</StartingPowerFactor>
<KWm>450</KWm>
<Efficiency xsi:nil="true" />
<IsLowInertia>false</IsLowInertia>
<MotorStandard>NEMA</MotorStandard>
<MotorStartingMethod>VariableFrequencyDrive</MotorStartingMethod>
<NEMAMotorCode>F</NEMAMotorCode>
<SolidStateStarterPercent>0</SolidStateStarterPercent>
<LockedRotorKVAPerHP>5.3</LockedRotorKVAPerHP>
</Load>
<Load xsi:type="ThreePhaseMotorLoad">
<Name>Motor 450 KW Pump</Name>
<Comments />
<Quantity>1</Quantity>
<Voltage>
<Name>240 Volt 3 Phase 12w 60Hz</Name>
<RangeDescription>120/240v</RangeDescription>
<V3Id>3</V3Id>
<Value>240</Value>
<V3Value>480</V3Value>
<Connection>Delta</Connection>
<Phase>3</Phase>
<VoltageCode>J</VoltageCode>
<Active>true</Active>
<Frequency>60</Frequency>
<PowerFactor>0.8000</PowerFactor>
<UL2200>true</UL2200>
<Default>true</Default>
<TempRiseIds>
<TempRiseId>B</TempRiseId>
<TempRiseId>C</TempRiseId>
<TempRiseId>D</TempRiseId>
<TempRiseId>E</TempRiseId>
</TempRiseIds>
</Voltage>
<IsNonLinear>true</IsNonLinear>
<PriorityProperty>KWm</PriorityProperty>
<KW>0</KW>
<RunningPowerFactor xsi:nil="true" />
<StartingPowerFactor>0.90</StartingPowerFactor>
<KWm>450</KWm>
<Efficiency xsi:nil="true" />
<IsLowInertia>false</IsLowInertia>
<MotorStandard>NEMA</MotorStandard>
<MotorStartingMethod>VariableFrequencyDrive</MotorStartingMethod>
<NEMAMotorCode>F</NEMAMotorCode>
<SolidStateStarterPercent>0</SolidStateStarterPercent>
<LockedRotorKVAPerHP>5.3</LockedRotorKVAPerHP>
</Load>
</Loads>
<VoltageDip>20</VoltageDip>
</Step>
您会注意到它的不同之处在于 VoltageDip 和 Loads 的顺序不同。所以它似乎与模式中设置的序列不匹配。在用户反序列化 Xml 字符串后发生的事情是,Name、Loads 和 VoltageDip 属性被设置为它们的默认值(引用类型和字符串为 null,int 为 0),而不是序列化过程中保存的值。
使用该应用程序的每个人都使用完全相同的源代码。
谁能告诉我发生了什么事?为什么不同用户/机器之间的序列化时元素的顺序会发生变化?为什么反序列化过程不能在它发生时处理它?<>
>
最佳答案
尝试在属性的 XmlElement 属性上使用 order 例如 -
[XmlElement(Order = 1)]
public string Prop1{get;set;}
[XmlElement(Order = 2)]
public string Prop1{get;set;}
关于c# - Xml序列化序列问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5342930/
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search
由于fast-stemmer的问题,我很难安装我想要的任何rubygem。我把我得到的错误放在下面。Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingfast-stemmer:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcreatingMakefilemake"DESTDIR="cleanmake"DESTDIR=
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub
如何在ruby中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL
我正在尝试在Ruby中复制Convert.ToBase64String()行为。这是我的C#代码:varsha1=newSHA1CryptoServiceProvider();varpasswordBytes=Encoding.UTF8.GetBytes("password");varpasswordHash=sha1.ComputeHash(passwordBytes);returnConvert.ToBase64String(passwordHash);//returns"W6ph5Mm5Pz8GgiULbPgzG37mj9g="当我在Ruby中尝试同样的事情时,我得到了相同sha
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我意识到这可能是一个非常基本的问题,但我现在已经花了几天时间回过头来解决这个问题,但出于某种原因,Google就是没有帮助我。(我认为部分问题在于我是一个初学者,我不知道该问什么......)我也看过O'Reilly的RubyCookbook和RailsAPI,但我仍然停留在这个问题上.我找到了一些关于多态关系的信息,但它似乎不是我需要的(尽管如果我错了请告诉我)。我正在尝试调整MichaelHartl'stutorial创建一个包含用户、文章和评论的博客应用程序(不使用脚手架)。我希望评论既属于用户又属于文章。我的主要问题是:我不知道如何将当前文章的ID放入评论Controller。