XSD.exe utility insights  
Author Message
brajeshkumar69





PostPosted: ASMX Web Services and XML Serialization, XSD.exe utility insights Top

Hi,

I used XSD utility in .NET framework 2.0 on a DLL, which has the following objects.
class A
{
string name;
string ID;
}

class B : A
{
int age;
int year;
}
class C: A
{
int month;
}
and so on..
Now, when I create XSD, it includes class A as base object in both Class B and Class C, which is not, what I want. Is there any way that I could create XSD, so that the members
of Class A are included in class B and class C
Secondly, I couldn't figure out the logic behind "minoccurs" and "maxooccurs" numbers generated in XSD file.

Thanks,

-Brajesh


.NET Development12  
 
 
Alex DeJarnatt - MSFT





PostPosted: ASMX Web Services and XML Serialization, XSD.exe utility insights Top

Hi,

- xsd.exe is designed to preserve the class hierarchy in XSD so you can't turn that off other than to remove the class hierarchy in your code.

- IIRC, value types (which cannot be null in .net) have minOccurs="1" and reference types (which can be null) have minOccurs="0". This means that when your string values are null, the elements won't be written at all. maxOccurs="1" unless the type is an array or collection in which case it will be maxOccurs="unbounded".

hope this helps

Alex



 
 
brajeshkumar69





PostPosted: ASMX Web Services and XML Serialization, XSD.exe utility insights Top

Alex,

Thanks for your answers!
Is there any document about it on MSDN or somewhere else (like a book), which I could look
Is there any way to force the defaults
For example, I know that Name is string, but it must exist for an employee,
so can I set an attribute in the field, which would set Minoccurs to 1.

Another question, I tried to generate XSD, based on XML file and found that
MinOccurs and MaxOccurs was not set at all. Is there any way to force it to generate

Thanks,

-Brajesh

 
 
Elena Kharitidi





PostPosted: ASMX Web Services and XML Serialization, XSD.exe utility insights Top

When you say that the minOccurs and maxOccurs was not set at all, do you mean that the attributes were messing from the schema theattibutes have default values (1), so if you do not see the attributes in the schema, it means that they are set to 1.

In addition, if you want to know what combination of attributes to use to get the specific instance shape, you should start with xsd (describing the instance), generate Object Model form it, and see what attributes are used. It should work in 95% cases.

Thanks,

Elena