質問

2つのERPシステム間でデータを共有するWebサービスに取り組んでいます。最初のERPはWebサービスを呼び出します。Webサービスはデータオブジェクトをシリアル化し、2番目のERPに送信します。

データオブジェクトは次のようになります。

    <xs:complexType name="Parent">
        <xs:sequence>
            <xs:element ref="ta:ReceiptLine" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="Child">
        <xs:sequence>
            ...
            <xs:element name="SerialNo" type="xs:string" nillable="true" minOccurs="0"/>
            <xs:element name="Quantity" type="xs:int" nillable="false"/>
            ...
        </xs:sequence>
    </xs:complexType>
    ...
    <xs:element name="Child" type="ta:Child" nillable="true"/>

XSDによって生成されたクラス:

[System.Serializable]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://FSM4TA/DataObjects/")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="http://FSM4TA/DataObjects/", IsNullable=false)]
public partial class Parent {
    private Child[] child;

    [System.Xml.Serialization.XmlElementAttribute("Child", IsNullable=true)]
        public Child[] Child {
            get {return this.child;}
            set {this.child = value;}
}

[System.Serializable]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://FSM4TA/DataObjects/")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="http://FSM4TA/DataObjects/", IsNullable=true)]
    public partial class Child{
        private string serialNo;
        private int quantity;

        [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
        public string SerialNo {
            get {return this.serialNo;}
            set {this.serialNo = value;}
        }

        public int Quantity {
            get { return this.quantity;}
            set {this.quantity = value;}
        }
}

XmlSerializerでデータオブジェクトをシリアル化しています

問題::(シリアル化時)子オブジェクトが空の場合は常に(xsi:nil = <!> quot; true <!> quot;)XSDは子全体を生成しますとにかく構造。また、Quantityはnillable / nullableではないため、XSDは値として 0 を書き込みます...このように:

<Parent>
  <Child xsi:nil="true">
    <SerialNo xsi:nil="true" />
    <Quantity>0</Quantity>
  </Child>
</Parent>

次のようなものが得られると思っていました:

<Parent>
  </Child xsi:nil="true">
</Parent>

質問です:XSDがxsi:nil = <!> quot; true <!> quot; -Objectを解析しないようにする方法はありますか?

提案はありますか?

TIA

役に立ちましたか?

解決

OK、

すぐにわかりました! XmlElementAttributeで Quantity プロパティを明示的にマークする必要があります!

[XmlElement(IsNullable=false)]
public int Quantity {
        get { return this.quantity;}
        set {this.quantity = value;}
    }

これが自動的に生成されない理由はわかりません...

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top