XmlSerializer在xsi:type上窒息?

时间:2009-09-29 21:30:45

标签: .net silverlight xml-serialization

编辑:请参阅下面的Pavel的答案 - '类型未识别错误'是由我的解析代码中的类层次结构(我没有在此处包含)与我的XML模式之间的不匹配引起的。 “类型未识别”错误是一个红色的鲱鱼,但一旦我修复了东西,解析工作就好了。如果你因为你用Google搜索了这个错误信息而得到这个问题,那么请检查你的heirarchies!

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

  

未识别指定的类型:   名称= UTCTimeStamp_t',   命名空间= 'http://www.fixprotocol.org/ATDL-1-1/Core',   在<参数   的xmlns = 'http://www.fixprotocol.org/ATDL-1-1/Core' >

(违规的xsi:Type,“UTCTimeStamp_t”,在引用的XSD文件中定义,如XML所示。)

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

我可以进行更改,或者我可以应用解决方法来解析它吗?

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

这是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文件的片段:

  <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>

1 个答案:

答案 0 :(得分:2)

XmlSerializer不关心类型的XML Schema定义 - 它关心的只是类型的名称,以及映射到它的类声明。如果不查看您尝试反序列化的类的定义,并且完成XML序列化属性,就不可能说出问题所在。

相关问题