Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / September 2004

Tip: Looking for answers? Try searching our database.

XmlSchemaElement.SchemaType returns null - bug?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
eXavier - 08 Sep 2004 15:43 GMT
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
Zafar Abbas [MSFT] - 09 Sep 2004 01:19 GMT
You must compile your schema using XmlSchema.Compile and then access the ElementType property to obtain an instance of the XmlSchemaType corresponding to the type in the schema.

 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
eXavier - 09 Sep 2004 07:38 GMT
Thanks a lot, it works as I need.
However, MSDN class library is poor documentation for using SOM, is there some good source of information on working with SOM ?
I would rather avoid this try-fail approach next time.

eXavier

 You must compile your schema using XmlSchema.Compile and then access the ElementType property to obtain an instance of the XmlSchemaType corresponding to the type in the schema.

   "eXavier" <fhns@centrum.cz> wrote in message news:uAsqqIblEHA.3104@TK2MSFTNGP14.phx.gbl...
   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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.