Search

xsd.exe does not generate nested arrays for nested sequences by Sheng Jiang[MVP]

Closed
as Fixed Help for as Fixed

0
Sign in to vote
0
Sign in to vote
Sign in
to vote
Type: Bug
ID: 444237
Opened: 5/7/2009 12:13:25 PM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
When the input contains nested sequences, the code generator generates classes for a single sequences and lose the message's structure. The class can not pass schema validation after XML serialization.

The actual schema that I am working with are generated by Microsoft Biztalk's Visual Studio addin (http://technet.microsoft.com/en-us/library/bb669664.aspx).
Details (expand)
Product Language
English

Version

Visual Studio 2008 SP1
Operating System
Windows Server 2003
Operating System Language
English
Steps to Reproduce
Create a schema file as follows
<?xml version="1.0" encoding="utf-16" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="ADT_A08_23_GLO_DEF">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="1">
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element minOccurs="1" maxOccurs="1" name="IN1_Insurance" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="IN2_InsuranceAdditionalInfo" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="IN3_InsuranceAdditionalInfoCertification" type="xs:string" />
</xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

try to generate C# code from the schema
xsd xmlfile1.xsd /c
Actual Results
public partial class ADT_A08_23_GLO_DEF {

private string[] iN1_InsuranceField;

private string[] iN2_InsuranceAdditionalInfoField;

private string[] iN3_InsuranceAdditionalInfoCertificationField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("IN1_Insurance", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string[] IN1_Insurance {
get {
return this.iN1_InsuranceField;
}
set {
this.iN1_InsuranceField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("IN2_InsuranceAdditionalInfo", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string[] IN2_InsuranceAdditionalInfo {
get {
return this.iN2_InsuranceAdditionalInfoField;
}
set {
this.iN2_InsuranceAdditionalInfoField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("IN3_InsuranceAdditionalInfoCertification", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string[] IN3_InsuranceAdditionalInfoCertification {
get {
return this.iN3_InsuranceAdditionalInfoCertificationField;
}
set {
this.iN3_InsuranceAdditionalInfoCertificationField = value;
}
}
}
Expected Results
public partial class ADT_A08_23_GLO_DEF {
public ADT_A08_23_GLO_DEF_UnnamedSequence1{get,set}

}

public partial class ADT_A08_23_GLO_DEF_UnnamedSequence1{


private string iN1_InsuranceField;

private string[] iN2_InsuranceAdditionalInfoField;

private string[] iN3_InsuranceAdditionalInfoCertificationField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("IN1_Insurance", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string IN1_Insurance {
get {
return this.iN1_InsuranceField;
}
set {
this.iN1_InsuranceField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("IN2_InsuranceAdditionalInfo", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string[] IN2_InsuranceAdditionalInfo {
get {
return this.iN2_InsuranceAdditionalInfoField;
}
set {
this.iN2_InsuranceAdditionalInfoField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("IN3_InsuranceAdditionalInfoCertification", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string[] IN3_InsuranceAdditionalInfoCertification {
get {
return this.iN3_InsuranceAdditionalInfoCertificationField;
}
set {
this.iN3_InsuranceAdditionalInfoCertificationField = value;
}
}
}
TAP Code (if applicable)
 
      You can indicate your satisfaction with how Microsoft handled this issue by completing this quick 3 question survey. [Details]

 

File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 5/8/2009 at 12:53 AM
Thanks for your feedback.

We are escalating this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Thank you,
Visual Studio Product Team
Posted by Microsoft on 5/14/2009 at 12:12 AM
Hello,
I can see the resulting output from the schema that you attached. The resulting type shouldn't generate a validation error. Can you please attach the XML and serialization code where you are seeing this error.
Also, is a possible workaround for you to remove the outer sequence?

thanks,
     Ramesh
Posted by Sheng Jiang[MVP] on 5/14/2009 at 6:36 AM
The actual schema is shipped with Microsoft BizTalk Server 2006's HL7 adapter. I got type cast error when deserializing a ORU_R01_23_GLO_DEF message part to the XSD-generated type, and serializing the XSD-generated ACK_24_GLO_DEF class. Looks like the serializer does not like multiple layer of sequences, which is quite common in HL7 segments.

And in case you did not notice, the xsd generated class has a different structure. It has only one layer of sequence in one type. I don't think the class can be serialized back to multiple layer of sequences at all.
Posted by Microsoft on 5/15/2009 at 5:07 PM
The inability to handle nested types is a bug in xsd.exe. Thank you for reporting that.
To workaround this issue, please re-define the nested types as top level types.

thanks,
     Ramesh
Posted by Sheng Jiang[MVP] on 5/16/2009 at 5:39 PM
Thanks, but I have no control over the source schema as it is part of Microsoft BizTalk Server. I am not sure BizTalk's HL7 adapter can parse messages into my schema.
Posted by Microsoft on 5/18/2009 at 9:54 AM
Do you have the ability to customize the schema generated by Biztalk as described in these articles?
http://geekswithblogs.net/carmelhl/articles/102076.aspx
http://blogs.microsoft.co.il/blogs/carmelh/archive/2008/11/11/creating-custom-hl7-schema.aspx

thanks,
     Ramesh
Posted by Sheng Jiang[MVP] on 5/18/2009 at 10:26 AM
Thanks, I am creating my own single-level schema right now for better serialization and performance. I need to write my own XML transform because BizTalk's mapper has problems with mapping nested sequence as well. I will try the suggested approach when I am not facing a deadline.