473,505 Members | 15,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlSchemaElement.SchemaType returns null - bug?

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
Nov 16 '05 #1
2 1606
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" <fh**@centrum.cz> wrote in message news:uA**************@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
Nov 16 '05 #2
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

"Zafar Abbas [MSFT]" <za****@microsoft.com> wrote in message news:%2******************@TK2MSFTNGP14.phx.gbl...
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" <fh**@centrum.cz> wrote in message news:uA**************@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
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
434
by: eXavier | last post by:
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...
0
1250
by: Rein Petersen | last post by:
Hi Folks, I'm reading a schema using SOM (System.Xml.Schema) and there are namespaced attributes that I need to access but I'm having problems with the UnhandledAttributes property - that is is...
1
1384
by: Rein Petersen | last post by:
Somebody please tell me what is the matter with the System.Xml.Schema.XmlSchemaElement.UnhandledAttributes property. I don't seem to be able to access no matter how I try... Rein
1
2419
by: Christian Lammel | last post by:
OK, repost: > I implemented a schema helper function GetDeclaration (similar to MSXML), > that finds a XmlSchemaElement for a given XmlElement, using a > XmlSchemaCollection. There is one kind...
4
7111
by: ezra epstein | last post by:
Aother head banger for me. Below is a complete example of the code Using Postgres 7.4, the function "test" gets this: psql:temp3.sql:10: ERROR: syntax error at or near "%" at character 135...
1
3341
by: Sam Vanhoutte | last post by:
Hello, I am generating an XML schema for the use in Biztalk 2004. Everything works, except for one simple thing. I cannot add XmlSchemaElements to a XmlSchemaComplexType. This is necessary...
1
1724
by: Josh | last post by:
Is there anyway to get the correct XmlSchemaElement from an XSD that corresponds to an element within an Xml Document Instance? I want to automatically generate a UI for an Xml Instance based...
10
4560
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acfctNZ_HV05186465.asp "If the value of the variant argument is Null, the Nz function returns the number zero or a...
4
3324
by: Henning M | last post by:
Hej All Im relativ new to VB.net and im trying to collect som device information using cfgmgr32.dll I use - Declare Function GetListLength Lib "cfgmgr32.dll" Alias...
9
3789
by: Francois Grieu | last post by:
When running the following code under MinGW, I get realloc(p,0) returned NULL Is that a non-conformance? TIA, Francois Grieu #include <stdio.h> #include <stdlib.h>
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.