0

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 を使用してデータ オブジェクトをシリアル化しています

問題は次のとおりです: (シリアル化時) Child オブジェクトが空の場合 (xsi:nil="true") のたびに、XSD はとにかく Child 構造全体を生成します。また、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="true"-Object を解析しないようにする方法はありますか??

助言がありますか?

ティア

4

1 に答える 1

1

わかった、

分かりました!XmlElementAttributeを使用してQuantityプロパティを明示的にマークする必要があります。

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

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

于 2009-04-15T09:46:27.950 に答える