在使用Xsd2Code从xsd生成代码时,我遇到了一个问题。xsd如下所示:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:ns1="urn:oasis:names:specification:ubl:schema:xsd:CountryIdentificationCode-1.0"
xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:LocationIdentificationCode-1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig.xsd" />
.......
</xs:schema>当我尝试序列化生成的类的实例时,我遇到了这个错误:
"Cannot serialize object of type 'MyXSD.SignatureValueType'.
Consider changing type of XmlText member 'MyXSD.SignatureValueType.Value' from System.Byte[] to string or string array."错误发生在这里:
[System.Xml.Serialization.XmlTextAttribute(DataType = "base64Binary")]
public byte[] Value
{
get
{
return this.valueField;
}
set
{
this.valueField = value;
}
}如果我将该属性更改为:
[System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")]..i获取其他错误:
Type of choice identifier 'ItemsElementName' is inconsistent with type of 'Items'.
Please use array of System.Collections.Generic.List`1[[MyXSD.ItemsChoiceType2, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].有没有人成功地将Xsd2Code与xmldsig一起使用?如果可能的话,我宁愿用Xsd2Code生成器来解决这个问题,而不是手动解决。还有没有别的选择?
发布于 2012-08-10 15:24:50
您是否尝试过仅使用xsd.exe?(http://msdn.microsoft.com/fr-fr/library/x6c1kb0s%28v=vs.80%29.aspx)
您能用失败的xsd代码的一部分来更新您的问题吗?
发布于 2014-07-05 11:01:42
问题出在文件顶部的DOCTYPE定义。
<!DOCTYPE schema
[
<!ATTLIST schema
xmlns:ds CDATA #FIXED "http://www.w3.org/2000/09/xmldsig#">
<!ENTITY dsig 'http://www.w3.org/2000/09/xmldsig#'>
<!ENTITY % p ''>
<!ENTITY % s ''>
]>将其注释掉,代码生成器就可以工作了。这个问题在2009年被报告给了xsd2code:https://xsd2code.codeplex.com/discussions/45133。这似乎仍然是一个悬而未决的问题。
发布于 2015-06-23 19:57:39
在数组选项中,将选项'CollectionObjectType‘设置为’Xsd2Code‘而不是'List’。
https://stackoverflow.com/questions/11896941
复制相似问题