Xsd2Code and xmldsig

為{幸葍}努か 提交于 2019-12-24 10:34:06

问题


I have a problem with generating code from xsd with Xsd2Code. The xsd looks like this:

<?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>

The error I fet when I try to serialize the instance of a generated class:

"Cannot serialize object of type 'MyXSD.SignatureValueType'. 
 Consider changing type of XmlText member 'MyXSD.SignatureValueType.Value' from System.Byte[] to string or string array."

The error happens here:

[System.Xml.Serialization.XmlTextAttribute(DataType = "base64Binary")]
public byte[] Value
{
    get
    {
        return this.valueField;
    }
    set
    {
        this.valueField = value;
    }
}

Event if I change that attribute to:

[System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")]

..i get other error:

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]].

Did anybody successfully use Xsd2Code with xmldsig? If possible I would rather solve this with Xsd2Code generator and not manually. Is there any other option?


回答1:


Have you tried to use only xsd.exe ? (http://msdn.microsoft.com/fr-fr/library/x6c1kb0s%28v=vs.80%29.aspx)

Can you update your question with the part of the failing xsd code ?




回答2:


The problem is the DOCTYPE definition at the top of the file.

<!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 ''>
  ]>

Comment this out and the code generation will work. This problem was reported to xsd2code in 2009: https://xsd2code.codeplex.com/discussions/45133. It appears that it continues to be an unresolved issue.




回答3:


In Xsd2Code options, set option 'CollectionObjectType' as 'Array' instead of 'List'.



来源:https://stackoverflow.com/questions/11896941/xsd2code-and-xmldsig

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!