【问题标题】:XmlSerializer is not Setting Specified Attribute to trueXmlSerializer 未将指定属性设置为 true
【发布时间】:2015-09-03 14:34:01
【问题描述】:

使用 VS 2013。
我们正在通过 Web Reference 使用一些 wsdl 并获取 ws 的所有类。
我们为 ws 层次结构属性设置了值,但该属性未序列化。
我看到here 属性未序列化的原因之一是:
“它有一个返回 false 的公共 bool FooSpecified {get;set;} 属性或字段。”
因此,如果我们设置层级属性,它不会在 XML 中表示:

familyInformation = new amadeus.Fare_SellByFareSearchFareFamiliesFamilyInformation
                   {
                      fareFamilyname = "XXXX",
                      hierarchy = 2
                   }



public decimal hierarchy {
        get {
            return this.hierarchyField;
        }
        set {
            this.hierarchyField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public bool hierarchySpecified {
        get {
            return this.hierarchyFieldSpecified;
        }
        set {
            this.hierarchyFieldSpecified = value;
        }
    }

<familyInformation>
  <fareFamilyname>XXXX</fareFamilyname>
</familyInformation>

请帮助如何获取层级属性序列化

【问题讨论】:

    标签: xml visual-studio-2013 xmlserializer


    【解决方案1】:

    您需要将 hierarchyhierarchySpecified 都设置为 truehierarchy 被声明为模式中的可选属性,因此引入 hierarchySpecified 让序列化程序知道您是否希望在 XML 中包含它(使用 truefalse 值)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-06
      • 2021-09-28
      • 2017-01-02
      • 1970-01-01
      • 1970-01-01
      • 2017-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多