E
eXavier
Hi all,
I wrote some generator of classes from XSD files but encountred unexpected (for me) values in parsed DOM.
First I load XSD with XmlSchema.Read() method, then iterate through XmlSchemaElements. I have a function
IsComplex() which return bool value if it has simple content (e.g. type string, int,...) or complex one (sequence,
choice, ..). This function looks like this:
bool IsComplex(XmlSchemaElement el) {
if (el.SchemaType is XmlSchemaComplexType) {
XmlSchemaComplexType t = (XmlSchemaComplexType)el.SchemaType;
if (t.ContentModel is XmlSchemaSimpleContent)
return false;
else
return true;
}
else
return false;
}
but when I use definition of type within XSD, SchemaType property of element returns null. I would expect here
instance of XmlSchemaComplexType. However SchemaTypeName is not null and contains correct value
(PackageList for example bellow).
Is it correct behaviour ? Is there better approach how to recognize content of schema element ?
Here's sample of XSD:
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://test.shipments" targetNamespace="http://test.shipments" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shipments">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="shipment">
<xs:complexType>
<xs:sequence>
<xs:element name="shipment_reference" type="xs:string" />
<xs:element name="packages" type="PackageList" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="PackageList">
<xs:sequence>
<xs:element name="package_reference" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
Thanks for any help,
eXavier
I wrote some generator of classes from XSD files but encountred unexpected (for me) values in parsed DOM.
First I load XSD with XmlSchema.Read() method, then iterate through XmlSchemaElements. I have a function
IsComplex() which return bool value if it has simple content (e.g. type string, int,...) or complex one (sequence,
choice, ..). This function looks like this:
bool IsComplex(XmlSchemaElement el) {
if (el.SchemaType is XmlSchemaComplexType) {
XmlSchemaComplexType t = (XmlSchemaComplexType)el.SchemaType;
if (t.ContentModel is XmlSchemaSimpleContent)
return false;
else
return true;
}
else
return false;
}
but when I use definition of type within XSD, SchemaType property of element returns null. I would expect here
instance of XmlSchemaComplexType. However SchemaTypeName is not null and contains correct value
(PackageList for example bellow).
Is it correct behaviour ? Is there better approach how to recognize content of schema element ?
Here's sample of XSD:
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://test.shipments" targetNamespace="http://test.shipments" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shipments">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="shipment">
<xs:complexType>
<xs:sequence>
<xs:element name="shipment_reference" type="xs:string" />
<xs:element name="packages" type="PackageList" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="PackageList">
<xs:sequence>
<xs:element name="package_reference" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
Thanks for any help,
eXavier