<bdo id='Yma85'></bdo><ul id='Yma85'></ul>
  • <i id='Yma85'><tr id='Yma85'><dt id='Yma85'><q id='Yma85'><span id='Yma85'><b id='Yma85'><form id='Yma85'><ins id='Yma85'></ins><ul id='Yma85'></ul><sub id='Yma85'></sub></form><legend id='Yma85'></legend><bdo id='Yma85'><pre id='Yma85'><center id='Yma85'></center></pre></bdo></b><th id='Yma85'></th></span></q></dt></tr></i><div id='Yma85'><tfoot id='Yma85'></tfoot><dl id='Yma85'><fieldset id='Yma85'></fieldset></dl></div>
    1. <legend id='Yma85'><style id='Yma85'><dir id='Yma85'><q id='Yma85'></q></dir></style></legend>
    2. <tfoot id='Yma85'></tfoot>

      <small id='Yma85'></small><noframes id='Yma85'>

        使用 .NET XmlSerializer 反序列化时使用多个命名空间

        Use multiple namespaces when deserializing with .NET XmlSerializer(使用 .NET XmlSerializer 反序列化时使用多个命名空间)

            <legend id='Rtx9f'><style id='Rtx9f'><dir id='Rtx9f'><q id='Rtx9f'></q></dir></style></legend>
                <bdo id='Rtx9f'></bdo><ul id='Rtx9f'></ul>

                <small id='Rtx9f'></small><noframes id='Rtx9f'>

              • <i id='Rtx9f'><tr id='Rtx9f'><dt id='Rtx9f'><q id='Rtx9f'><span id='Rtx9f'><b id='Rtx9f'><form id='Rtx9f'><ins id='Rtx9f'></ins><ul id='Rtx9f'></ul><sub id='Rtx9f'></sub></form><legend id='Rtx9f'></legend><bdo id='Rtx9f'><pre id='Rtx9f'><center id='Rtx9f'></center></pre></bdo></b><th id='Rtx9f'></th></span></q></dt></tr></i><div id='Rtx9f'><tfoot id='Rtx9f'></tfoot><dl id='Rtx9f'><fieldset id='Rtx9f'></fieldset></dl></div>
              • <tfoot id='Rtx9f'></tfoot>
                  <tbody id='Rtx9f'></tbody>
                  本文介绍了使用 .NET XmlSerializer 反序列化时使用多个命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用两个命名空间来反序列化 XML,就像这样

                  I'm trying to deserialize XML with two namespaces, like this

                  <records xmlns="http://www.foo.com/xml/records/1.1">
                      <record xmlns="http://www.foo.com/xml/record/1.1">
                  

                  有时是旧版本

                  <records xmlns="http://www.foo.com/xml/records/1.1">
                      <record xmlns="http://www.foo.com/xml/record/1.0">
                  

                  我的 Records.cs 类有

                  My Records.cs class has

                  [XmlRoot(ElementName = "records", Namespace = "http://www.foo.com/xml/records/1.1")]
                  public class Records
                  {
                      [System.Xml.Serialization.XmlElementAttribute("record")]
                      public List<Record> Records { get; set; }
                  }
                  

                  我希望记录列表能够包含 1.0 版或 1.1 版记录

                  I want the Records list to be able to contain either a version 1.0 or version 1.1 Record

                  /// <remarks/>
                  [XmlRoot(IsNullable = false, ElementName = "record", Namespace = "http://www.foo.com/xml/record/1.0")]
                  public partial class Record
                  {
                  
                  
                      /// <remarks/>
                  
                      public Record()
                      {
                  
                      }
                  }
                  
                  /// <remarks/>
                  [XmlRoot(IsNullable = false, ElementName = "record", Namespace = "http://www.foo.com/xml/record/1.1")]
                  public partial class Record11 : Record
                  {
                      /// <remarks/>
                      public Record11()
                      {
                      }
                  }
                  

                  所以我假设子类化记录会起作用.

                  so I assumed subclassing the record would work.

                  反序列化时出现反射异常,异常指向 XmlChoiceIdentifier 属性.但是,这似乎与枚举有关.

                  I get a Reflection exception when deserializing and the exception points me to the XmlChoiceIdentifier attribute. However, that seems related to enums.

                  任何人都知道如何做我想做的事(支持反序列化同一架构的多个版本?)

                  Anyone know how to do what I want to do (support deserializing multiple versions of the same schema?)

                  谢谢.

                  推荐答案

                  [XmlRoot] 在您的示例中的 RecordRecord11 属性将被忽略.只有当元素是树中的根时,它们才有意义.你需要做的是:

                  [XmlRoot] attributes on both Record and Record11 in your example will be ignored. They only have meaning when element is a root in the tree. What you rather need to do is this:

                  [XmlRoot(ElementName = "records",
                           Namespace = "http://www.foo.com/xml/records/1.1")]
                  public class Records
                  {
                      [XmlElement(Type = typeof(Record),
                                  ElementName = "record",
                                  Namespace = "http://www.foo.com/xml/records/1.0")]
                      [XmlElement(Type = typeof(Record11),
                                  ElementName = "record",
                                  Namespace = "http://www.foo.com/xml/records/1.1")]
                      public List<Record> Records { get; set; }
                  }
                  

                  这篇关于使用 .NET XmlSerializer 反序列化时使用多个命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  C# namespace alias - what#39;s the point?(C# 命名空间别名 - 有什么意义?)
                  Using Xpath With Default Namespace in C#(在 C# 中使用具有默认命名空间的 Xpath)
                  Generating an EDMX from a DB2 Database(从 DB2 数据库生成 EDMX)
                  IBM .NET Data Provider Connection String issue with Library List(库列表的 IBM .NET 数据提供程序连接字符串问题)
                  .NET DB2 OLEDB pre-requisites(.NET DB2 OLEDB 先决条件)
                  Referring to Code in IBM.Data.DB2 makes that Assembly Unavailable to the rest of my Solution(引用 IBM.Data.DB2 中的代码使该程序集对我的解决方案的其余部分不可用)

                        • <bdo id='WFPNI'></bdo><ul id='WFPNI'></ul>

                          • <legend id='WFPNI'><style id='WFPNI'><dir id='WFPNI'><q id='WFPNI'></q></dir></style></legend>
                              <tbody id='WFPNI'></tbody>
                            <tfoot id='WFPNI'></tfoot>
                          • <i id='WFPNI'><tr id='WFPNI'><dt id='WFPNI'><q id='WFPNI'><span id='WFPNI'><b id='WFPNI'><form id='WFPNI'><ins id='WFPNI'></ins><ul id='WFPNI'></ul><sub id='WFPNI'></sub></form><legend id='WFPNI'></legend><bdo id='WFPNI'><pre id='WFPNI'><center id='WFPNI'></center></pre></bdo></b><th id='WFPNI'></th></span></q></dt></tr></i><div id='WFPNI'><tfoot id='WFPNI'></tfoot><dl id='WFPNI'><fieldset id='WFPNI'></fieldset></dl></div>

                          • <small id='WFPNI'></small><noframes id='WFPNI'>