C# - 无法解析使用Microsoft xsd.exe生成的XML文件

时间:2013-03-11 13:59:26

标签: c# xml serialization xsd deserialization

我使用XSD文件中的xsd.exe创建了一个C#类。根元素称为ODX。我希望能够通过以类似于此的方式解析XML文件来填充ODX对象:

namespace OdxLib
{
    class Program
    {
        static void Main(string[] args)
        {
            ODX odxDocument;
            using (var stream = new FileStream("C:\\MCA2014.40_NEW.odx", FileMode.Open))
            {
                var serializer = new XmlSerializer(typeof(ODX));
                odxDocument = (ODX) serializer.Deserialize(stream);
                Console.WriteLine(odxDocument.ToString());
            }
        }
    }
}

这对我来说是正确的。 无论如何,我得到以下错误:

InvalidOperationException
Unable to generate a tempoprary class

error CS0030: Unable to convert type 'it.intecs.odx.DISABLEDAUDIENCEREFS' to 'it.intecs.odx.ENABLEDAUDIENCEREFS'.
error CS0029: Unable to implicitly convert type 'it.intecs.odx.ENABLEDAUDIENCEREFS' to 'it.intecs.odx.DISABLEDAUDIENCEREFS'.

我不明白这个错误的原因。

这是ODX文件的示例(完整文件超过150000行):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ODX MODEL-VERSION="2.0.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="odx.xsd">
<!--created by CANdelaStudio::ODXExport201.dll 7.1.101 on 2012-06-12T11:33:41+02:00-->
  <?CANdelaTemplateManufacturer 12?>
  <?CANdelaTemplateName New ECU 2.9?>
  <?CANdelaTemplateVersion 3.0.0?>
  <?CANdelaProtocolStandard UDS?>
  <?ASAMOdxExport201.dll 7.1.101?>
  <DIAG-LAYER-CONTAINER ID="_XXX2014_990">
    <SHORT-NAME>XXX</SHORT-NAME>
    <LONG-NAME>XXX</LONG-NAME>
    <ADMIN-DATA>
      <LANGUAGE>eng</LANGUAGE>
      <DOC-REVISIONS>
        <DOC-REVISION>
        ...
        <COMPARAM-REFS>
          <COMPARAM-REF ID-REF="XYZ" DOCREF="UDS_CPS" DOCTYPE="COMPARAM-SPEC">
            <VALUE>500000</VALUE>
            <DESC>
              <p>
                250000 and 500000 baud shall be supported XXX
                <br/>
              </p>
            </DESC>
            <PROTOCOL-SNREF SHORT-NAME="Diagnostic_UDS_on_CAN"/>
          </COMPARAM-REF>

这是xsd文件在xsd文件中生成的类的一部分:

namespace it.intecs.odx {
    using System.Xml.Serialization;


    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
    public partial class ODX {

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("COMPARAM-SPEC", typeof(COMPARAMSPEC), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        [System.Xml.Serialization.XmlElementAttribute("COMPARAM-SUBSET", typeof(COMPARAMSUBSET), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        [System.Xml.Serialization.XmlElementAttribute("DIAG-LAYER-CONTAINER", typeof(DIAGLAYERCONTAINER), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        [System.Xml.Serialization.XmlElementAttribute("ECU-CONFIG", typeof(ECUCONFIG), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        [System.Xml.Serialization.XmlElementAttribute("FLASH", typeof(FLASH), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        [System.Xml.Serialization.XmlElementAttribute("FUNCTION-DICTIONARY", typeof(FUNCTIONDICTIONARY), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        [System.Xml.Serialization.XmlElementAttribute("MULTIPLE-ECU-JOB-SPEC", typeof(MULTIPLEECUJOBSPEC), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        [System.Xml.Serialization.XmlElementAttribute("VEHICLE-INFO-SPEC", typeof(VEHICLEINFOSPEC), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public ODXCATEGORY Item;

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute("MODEL-VERSION")]
        public string MODELVERSION;

        public ODX() {
            this.MODELVERSION = "2.2.0";
        }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(TypeName="COMPARAM-SPEC")]
    public partial class COMPARAMSPEC : ODXCATEGORY {

        /// <remarks/>
        [System.Xml.Serialization.XmlArrayAttribute("PROT-STACKS", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        [System.Xml.Serialization.XmlArrayItemAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
        public PROTSTACK[] PROTSTACKS;
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(TypeName="PROT-STACK")]
    public partial class PROTSTACK {

0 个答案:

没有答案