xsd.exe生成的XML反序列化器返回null

时间:2018-01-12 00:19:15

标签: c# xml xml-deserialization

我有一个与xsd.exe一起使用的XSD来生成XML反序列化器。但是,在运行时,它不会反序列化Bar或Timer定义。

XSD的相关部分如下:

this.hardwareTerminalWS.unsubscribe();

生成的partial类如下所示:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://schemas.koboltentertainment.com"
    elementFormDefault="qualified"
    xmlns="http://schemas.koboltentertainment.com"
    xmlns:mstns="http://schemas.koboltentertainment.com"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <!-- Bar Definition -->
  <xs:complexType name="Bar">
    <xs:sequence>
      <xs:element name="MaskAnim" type="Anim" />
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" />
    <xs:attribute name="anim" type="xs:positiveInteger" />
    <xs:attribute name="recoverAnim" type="xs:positiveInteger" />
    <xs:attribute name="min" type="xs:int" />
    <xs:attribute name="max" type="xs:int" />
    <xs:attribute name="valueBind" type="xs:string" />
    <xs:attribute name="pos" type="vector" />
    <xs:attribute name="layer" type="xs:byte" />
    <xs:attribute name="width" type="xs:int" />
  </xs:complexType>

  <!-- CONTAINAZ -->
  <xs:element name="Containers">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="Container" minOccurs="1" maxOccurs="unbounded" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <!-- Container -->
  <xs:element name="Container">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Bar" type="Bar" minOccurs="1" maxOccurs="1" />
      </xs:sequence>
      <xs:attribute name="name" type="xs:string"/>
      <xs:attribute name="id" type="xs:positiveInteger" />
      <xs:attribute name="pos" type ="vector"/>
      <xs:attribute name="layer" type="xs:byte" />
      <xs:attribute name="anim" type="xs:positiveInteger" />
      <xs:attribute name="alignment" type="alignment" />
    </xs:complexType>
  </xs:element>

最后,XML如下所示:

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.koboltentertainment.com")]
public partial class Bar {
    // data members, etc.
}

容器,容器及其包含的大部分内容都是正确反序列化的,但Bar不是。它总是在运行时返回null。为什么不反序列化?

1 个答案:

答案 0 :(得分:1)

我对xsd并不熟悉。但是,当某些内容通常不会反序列化时,因为数据无效。

在这种情况下,我猜测它是因为Bar.minBar.max被定义为int s,而"Players[1].Constants.Data.Life"看起来并不像中间体

相关问题