如何控制XSI XML序列化行为:nill =
-
20-08-2019 - |
题
我正在一个web服务共享2 ERP系统之间的数据。第一ERP调用web服务,其将数据串行化对象,并将其发送到所述第二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:无=“真”)的XSD无论如何产生子整结构。而且因为数量并不是的nillable / null的XSD写的 0 的价值......这样的:
<Parent>
<Child xsi:nil="true">
<SerialNo xsi:nil="true" />
<Quantity>0</Quantity>
</Child>
</Parent>
我希望得到的东西是这样的:
<Parent>
</Child xsi:nil="true">
</Parent>
<强>问题是强>:有一种方法,以防止从XSD解析一个xsi:无= “真” -object ??
任何建议?
TIA
解决方案
确定,
我现在! 你必须标记的数量的与XmlElementAttribute明确财产!
[XmlElement(IsNullable=false)]
public int Quantity {
get { return this.quantity;}
set {this.quantity = value;}
}
不知道为什么这并没有被自动生成...
不隶属于 StackOverflow