繁体   English   中英

Xsd.exe生成错误的实现<xs:list>

[英]Xsd.exe generates buggy implementation of <xs:list>

这是Xsd.exe生成的示例(也是Xsd2Code,但使用通用List <>)。

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="xxxxxxxxxxxxxxxx")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="xxxxxxxxxxxxxxxx", IsNullable=false)]
public partial class ItemQuantity 
{

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string Units;

    /// <remarks/>
    [System.Xml.Serialization.XmlAnyAttributeAttribute()]
    public System.Xml.XmlAttribute[] AnyAttr;

    /// <remarks/>
    [System.Xml.Serialization.XmlTextAttribute()] // <-- this is the bug
    public double[] Text;   // <-- this is the bug corresponding to a <xs:list itemType=xs:double/> in the schema
}

我正在处理一个非常大的模式,它使用了几次xs:list来表示不同的原语...

并且所有这些不是string [](而不是double [] decimal [])的Text属性在运行时都会在与XmlSerializer一起使用时导致此异常:(我用英语翻译)成员Text无法使用属性进行编码XMLTEXT。 您可以将属性XmlText与基元,枚举,字符串数组或XmlNode数组一起使用。

你有什么建议我的?

我编辑了xsd.exe生成的代码并放入

[System.Xml.Serialization.XmlArrayItemAttribute("Double",typeof(double), IsNullable = false)]

代替

[System.Xml.Serialization.XmlTextAttribute()]

而且就我而言......它确实表现得更好......

<Test><Double>0.1</Double><Double>0.2</Double><Double>0.8</Double><Double>0.505</Double></Test>

但我应该确保在Test标签中包含所有列表仍然对我的架构有效...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM