简体   繁体   中英

Xsd2Code and xmldsig

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?

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 ?

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.

在Xsd2Code选项中,将选项“ CollectionObjectType”设置为“ Array”而不是“ List”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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