XmlSerializer在xsi:type上扼流了吗? [英] XmlSerializer chokes on xsi:type?

查看:53
本文介绍了XmlSerializer在xsi:type上扼流了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参阅下面的Pavel回答-无法识别类型错误"是由我的解析代码(此处未包括在内)中的类层次结构与XML模式之间的不匹配引起的.无法识别的类型"错误有点像是鲱鱼,但是一旦我解决了问题,解析就可以了.如果您是因为搜索过该错误消息而遇到此问题的,请仔细检查您的继承关系!

See Pavel's answer below -- the 'type not recognized error' was caused by a mismatch between the class heirarchy in my parsing code (which I did not include here) and my XML schema. The 'type not recognized' error was something of a red herring, but once I fixed things the parsing works just fine. If you get to this question because you've googled for that error message, triple-check your heirarchies!

我有下面显示的XML文件.当我在VS2008中查看它时,Intellisense不会报告任何错误.但是,当我尝试使用XmlSerializer.Deserialize解析它时,出现了异常:

I have the XML file shown below. When I view it in VS2008, Intellisense does not report any errors. However when I try to parse it with XmlSerializer.Deserialize, I get the exception:

无法识别指定的类型:name ='UTCTimeStamp_t',namespace =' http://www.fixprotocol.org/ATDL-1-1/Core',在< Parameterxmlns =' http://www.fixprotocol.org/ATDL-1-1/Core'>.

The specified type was not recognized: name='UTCTimeStamp_t', namespace='http://www.fixprotocol.org/ATDL-1-1/Core', at <Parameter xmlns='http://www.fixprotocol.org/ATDL-1-1/Core'>.

(有问题的xsi:Type"UTCTimeStamp_t"在引用的XSD文件中定义,如XML下方所示.)

(The offending xsi:Type, "UTCTimeStamp_t", is defined in the referenced XSD file as shown below the XML.)

为什么即使Intellisense显示XML有效,XmlSerializer仍拒绝XML?(我仔细检查了两者是否都获得了相同的XSD文件副本.)

Why does XmlSerializer reject the XML even though Intellisense shows it as being valid? (I double-checked that both are getting the same copy of the XSD file.)

是否可以进行更改或应用变通方法来解析?

Is there a change I can make, or a workaround I can apply, to get this to parse?

注意:我正在Silverlight3中执行此操作-该版本的序列化程序是否有任何特定限制?

NOTE: I am doing this in Silverlight3 -- are there any particular limitations to that version of the serializer?

这是XML:

<?xml version="1.0" encoding="utf-8"?>
<Strategies
 xmlns="http://www.fixprotocol.org/ATDL-1-1/Core"
  xmlns:core="http://www.fixprotocol.org/ATDL-1-1/Core"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xsi:schemaLocation="http://www.fixprotocol.org/ATDL-1-1/Core http://www.myserver.com/atdl-core-1-1.xsd"
  strategyIdentifierTag="7620"
  >

  <Strategy name="Tazer1" uiRep="Tazer" wireValue="Tazer" version="1" fixMsgType="D" providerID="ABC">

    <Parameter name="StartTime" xsi:type="core:UTCTimeStamp_t" fixTag="7602" use="required" localMktTz="America/New_York">
      <Description>Strategy Start Time</Description>
    </Parameter>
  </Strategy>

</Strategies>

这是XSD文件的代码段:

Here's the snippet of the XSD file:

  <xs:complexType name="UTCTimeStamp_t">
    <xs:complexContent>
      <xs:extension base="core:Parameter_t">
        <xs:attribute name="minValue" type="core:UTCTimeStamp"/>
        <xs:attribute name="maxValue" type="core:UTCTimeStamp"/>
        <xs:attribute name="dailyMinValue" type="core:LocalMktTime"/>
        <xs:attribute name="dailyMaxValue" type="core:LocalMktTime"/>
        <xs:attribute name="localMktTz" type="xs:string">
          <xs:annotation>
            <xs:documentation>
              These string values must correspond to time zone values from the zoneinfo database,
              also known as the tz database.
            </xs:documentation>
          </xs:annotation>
        </xs:attribute>
        <xs:attribute name="constValue" type="core:UTCTimeStamp"/>
        <xs:attribute name="dailyConstValue" type="core:LocalMktTime"/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

推荐答案

XmlSerializer 不关心类型的XML Schema定义-它关心的只是类型的名称和类映射到它的声明.如果不查看要反序列化的类的定义以及它们的XML序列化属性,就不可能说出问题所在.

XmlSerializer does not care about XML Schema definition of the type - all it cares about is the name of the type, and the class declaration that maps to it. It's not possible to say what the problem is without looking at the definition of the class(es) you're trying to deserialize, complete with their XML serialization attributes.

这篇关于XmlSerializer在xsi:type上扼流了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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