문제

저는 웹 서비스를 통해 2 개의 ERP 시스템간에 데이터를 공유하고 있습니다. 첫 번째 ERP는 WebService를 호출하여 데이터를 직렬화하여 두 번째 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 = "true") XSD는 어쨌든 전체 아동 구조를 생성합니다. 그리고 수량은 nillable/nullabable 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 ??

제안이 있습니까?

티아

도움이 되었습니까?

해결책

좋아요,

이제 알겠습니다! 당신은 표시해야합니다 수량 xmlelementattribute가있는 속성을 명시 적으로!

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

왜 이것이 자동으로 생성되지 않았는지 모르겠습니다 ...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top