Howto create instances of nested classes in autogenerated xsd clas

G

Guest

When I autogenerate class files from XSD schemas using XSD.EXE the generated
class doesn't generate instances of nested classes. Is there any way to
autocreate instances of nested classes also? I don't want to modify
autogenerated code because all changes would be lost when the class would be
regenerated.

Sample schema:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="XMLSchema1"
targetNamespace="http://tempuri.org/XMLSchema1.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema1.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="element1">
<xs:complexType>
<xs:sequence>
<xs:element name="element2">
<xs:complexType>
<xs:sequence />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Autogenerated class
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/XMLSchema1.xsd")
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/XMLSchema1.xsd", IsNullable=false)]
public class element1 {

/// <remarks/>
public element1Element2 element2;
}

/// <remarks/
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/XMLSchema1.xsd")]
public class element1Element2 {
}
 
O

Ollie Riches

In the example you have given there isn't any other elements under the
element called 'element2' so therefore the class definition is correct.

HTH

Ollie Riches
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top