473,386 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem with .NET Beta2 upgrade, with XSD traversal (LocalElements issue!!) :-(

Hello,

I had a program in .NET Beta1, where in I was programmatically traversing
the Xml Schema using the given code snippet.

However today with migration to Beta2, I am facing a compilation issue that
LocalElements property on XmlSchemaComplexType not found. I now dont know
how to traverse XSD programmatically!!!
- I have a 4 level heirarchy XSD with a mix and match of complex elements
containing content and attributes both!

Please do help. Our current application BREAKS and I cannot go ahead with
development which is in its important phase, to be delivered by tomorrow!!

I would like to know what way I can traverse an XSD in a generic fashion as
possible, so that I could go to 1st level, 2nd level, 3rd or 4th level with
same peice of foreach code. Some documentation would reallly help. Also why
the LocalElements is not supported, I see its only supported in Compact
framework....
===========================================
XmlReader reader = new XmlTextReader(fileName);
XmlSchemaSet schemaSet = new XmlSchemaSet();
XmlSchema schema = XmlSchema.Read(reader, null);
XmlSchemaObjectEnumerator itr = schema.Items.GetEnumerator();

//schema is added to schemaset
schemaSet.Add(schema);
// compile schemaset : some properties are enabled post compilation
schemaSet.Compile();

// A better way to Traverse the XSD
foreach (XmlSchemaElement parentElem in schema.Elements.Values)
{
XmlSchemaComplexType ct = parentElem.ElementSchemaType as
XmlSchemaComplexType;
if (ct != null)
{
foreach (XmlSchemaElement childElem in ct.LocalElements.Values)
{
string str = childElem.Name;
XmlSchemaComplexType ct1 = childElem.ElementSchemaType as
XmlSchemaComplexType;
Type type = null;
foreach (XmlSchemaElement gChildElem in ct1.LocalElements.Values)
{
if (gChildElem != null)
{
// Inner elements
string str1 = gChildElem.Name;
XmlSchemaComplexType ct2 = gChildElem.ElementSchemaType as
XmlSchemaComplexType;
foreach (XmlSchemaElement gGChildElem in ct2.LocalElements.Values)
{
decimal occurence = gGChildElem.MaxOccurs;
}
}//if
}//foreach
}//foreach
}//if ct !=null
}//foreach
===========================================

Thanks
Uma
Nov 12 '05 #1
2 1960
LocalElements property was removed from .Net Framwork beta2.
You can use the following code to construct a list of total local elements
in your schema, and a list of unique local elements names.

~Zafar

private static void PrintParticles(string url) {

XmlSchema schema = XmlSchema.Read(new XmlTextReader(url, new NameTable()),
new ValidationEventHandler(ValidationCallback));
schema.Compile(new ValidationEventHandler(ValidationCallback));
ArrayList elementDeclsInContentModel = new ArrayList();
Hashtable uniqueDecls = new Hashtable();

foreach(XmlSchemaType type in schema.SchemaTypes.Values) {
XmlSchemaComplexType complexType = type as XmlSchemaComplexType;
if (complexType != null) {
elementDeclsInContentModel.Clear();
uniqueDecls.Clear();
TraverseParticle(complexType.ContentTypeParticle,
elementDeclsInContentModel, uniqueDecls);
Console.WriteLine("No of element decls: " +
elementDeclsInContentModel.Count);
Console.WriteLine("No of unique element decls: " + uniqueDecls.Count);
}
}
}

private static void TraverseParticle(XmlSchemaParticle particle, ArrayList
elementDeclsInContentModel, Hashtable uniqueDecls) {

if (particle is XmlSchemaElement) {
XmlSchemaElement elem = particle as XmlSchemaElement;
elementDeclsInContentModel.Add(elem);
if (!uniqueDecls.ContainsKey(elem.QualifiedName)) {
uniqueDecls.Add(elem.QualifiedName, elem);
}
}
else if (particle is XmlSchemaGroupBase) { //xs:all, xs:choice, xs:sequence
XmlSchemaGroupBase baseParticle = particle as XmlSchemaGroupBase;
foreach(XmlSchemaParticle subParticle in baseParticle.Items) {
TraverseParticle(subParticle, elementDeclsInContentModel, uniqueDecls);
}
}
}

"Uma Abhyankar" <au**@persistent.co.in> wrote in message
news:ut**************@TK2MSFTNGP14.phx.gbl...
Hello,

I had a program in .NET Beta1, where in I was programmatically traversing
the Xml Schema using the given code snippet.

However today with migration to Beta2, I am facing a compilation issue that LocalElements property on XmlSchemaComplexType not found. I now dont know
how to traverse XSD programmatically!!!
- I have a 4 level heirarchy XSD with a mix and match of complex elements
containing content and attributes both!

Please do help. Our current application BREAKS and I cannot go ahead with
development which is in its important phase, to be delivered by tomorrow!!

I would like to know what way I can traverse an XSD in a generic fashion as possible, so that I could go to 1st level, 2nd level, 3rd or 4th level with same peice of foreach code. Some documentation would reallly help. Also why the LocalElements is not supported, I see its only supported in Compact
framework....
===========================================
XmlReader reader = new XmlTextReader(fileName);
XmlSchemaSet schemaSet = new XmlSchemaSet();
XmlSchema schema = XmlSchema.Read(reader, null);
XmlSchemaObjectEnumerator itr = schema.Items.GetEnumerator();

//schema is added to schemaset
schemaSet.Add(schema);
// compile schemaset : some properties are enabled post compilation
schemaSet.Compile();

// A better way to Traverse the XSD
foreach (XmlSchemaElement parentElem in schema.Elements.Values)
{
XmlSchemaComplexType ct = parentElem.ElementSchemaType as
XmlSchemaComplexType;
if (ct != null)
{
foreach (XmlSchemaElement childElem in ct.LocalElements.Values)
{
string str = childElem.Name;
XmlSchemaComplexType ct1 = childElem.ElementSchemaType as
XmlSchemaComplexType;
Type type = null;
foreach (XmlSchemaElement gChildElem in ct1.LocalElements.Values)
{
if (gChildElem != null)
{
// Inner elements
string str1 = gChildElem.Name;
XmlSchemaComplexType ct2 = gChildElem.ElementSchemaType as
XmlSchemaComplexType;
foreach (XmlSchemaElement gGChildElem in ct2.LocalElements.Values) {
decimal occurence = gGChildElem.MaxOccurs;
}
}//if
}//foreach
}//foreach
}//if ct !=null
}//foreach
===========================================

Thanks
Uma

Nov 12 '05 #2
You can play with the following code:

void Start()
{
XmlSchemaComplexType complexType;
foreach (XmlSchemaType type in xs.SchemaTypes.Values)
{
complexType = type as XmlSchemaComplexType;
if (complexType != null)
TraverseParticle(complexType.ContentTypeParticle);
}

foreach (XmlSchemaElement el in xs.Elements.Values)
TraverseParticle(el);
}

void TraverseParticle(complexType.ContentTypeParticle)
{
if (particle is XmlSchemaElement)
{
XmlSchemaElement elem = particle as XmlSchemaElement;

if (elem.RefName.IsEmpty)
{
XmlSchemaType type = (XmlSchemaType)elem.ElementSchemaType;
XmlSchemaComplexType complexType = type as XmlSchemaComplexType;
if (complexType != null && complexType.Name == null)
TraverseParticle(complexType.ContentTypeParticle);
}
}
else if (particle is XmlSchemaGroupBase)
{ //xs:all, xs:choice, xs:sequence
XmlSchemaGroupBase baseParticle = particle as XmlSchemaGroupBase;
foreach (XmlSchemaParticle subParticle in baseParticle.Items)
TraverseParticle(subParticle);
}
}

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

"Uma Abhyankar" <au**@persistent.co.in> wrote in message
news:ut**************@TK2MSFTNGP14.phx.gbl...
Hello,

I had a program in .NET Beta1, where in I was programmatically traversing
the Xml Schema using the given code snippet.

However today with migration to Beta2, I am facing a compilation issue
that LocalElements property on XmlSchemaComplexType not found. I now dont
know how to traverse XSD programmatically!!!
- I have a 4 level heirarchy XSD with a mix and match of complex elements
containing content and attributes both!

Please do help. Our current application BREAKS and I cannot go ahead with
development which is in its important phase, to be delivered by tomorrow!!

I would like to know what way I can traverse an XSD in a generic fashion
as possible, so that I could go to 1st level, 2nd level, 3rd or 4th level
with same peice of foreach code. Some documentation would reallly help.
Also why the LocalElements is not supported, I see its only supported in
Compact framework....
===========================================
XmlReader reader = new XmlTextReader(fileName);
XmlSchemaSet schemaSet = new XmlSchemaSet();
XmlSchema schema = XmlSchema.Read(reader, null);
XmlSchemaObjectEnumerator itr = schema.Items.GetEnumerator();

//schema is added to schemaset
schemaSet.Add(schema);
// compile schemaset : some properties are enabled post compilation
schemaSet.Compile();

// A better way to Traverse the XSD
foreach (XmlSchemaElement parentElem in schema.Elements.Values)
{
XmlSchemaComplexType ct = parentElem.ElementSchemaType as
XmlSchemaComplexType;
if (ct != null)
{
foreach (XmlSchemaElement childElem in ct.LocalElements.Values)
{
string str = childElem.Name;
XmlSchemaComplexType ct1 = childElem.ElementSchemaType as
XmlSchemaComplexType;
Type type = null;
foreach (XmlSchemaElement gChildElem in ct1.LocalElements.Values)
{
if (gChildElem != null)
{
// Inner elements
string str1 = gChildElem.Name;
XmlSchemaComplexType ct2 = gChildElem.ElementSchemaType as
XmlSchemaComplexType;
foreach (XmlSchemaElement gGChildElem in
ct2.LocalElements.Values)
{
decimal occurence = gGChildElem.MaxOccurs;
}
}//if
}//foreach
}//foreach
}//if ct !=null
}//foreach
===========================================

Thanks
Uma

Nov 12 '05 #3

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

Similar topics

3
by: Kulnor | last post by:
My hosting company upgraded yesterday to pHp 4.3.10. Since then, all my INSERT/UPDATE/DELET query on our MS-SQL database seem to fail. No specific error message is returned by...
0
by: Uma Abhyankar | last post by:
Hello, I had a program in .NET Beta1, where in I was programmatically traversing the Xml Schema using the given code snippet. However today with migration to Beta2, I am facing a compilation...
2
by: ivan | last post by:
I had 512 Mb memory running an Access 97 app. I just upgraded by installing another 512 MB (1024 MB total) and suddenly I am getting an out of memory message as Access tries to load. Help!!!
3
by: peesz | last post by:
After upgrade ODBC Client from version 7.2 to 8.1 (FixPack 10) a have problem with tables where primary key is set to timestamp filed. In version 7.2 TIMESTAMP was mapped in MS Access as...
0
by: Bernhard Hess | last post by:
I use following C# code behind an aspx file to send a *.pdf file to the Internet Explorer. The variable "buffer" is of type byte and is filled with the contents of a *.pdf file. ...
5
by: Benzi Eilon | last post by:
I have written a C# application which should run as a Windows Service. I must avoid having multiple instances of the application on one machine so I inserted the following code at the beginning of...
3
by: töff | last post by:
On my site http://www.sjcga.com I have a javascript-generated navigation menu in the top right corner. The menu works great in IE and Opera ... but in FireFox, on the 1st click, the menu jumps...
0
by: zaky | last post by:
I have a problem when upgrade to new version Postgres (v8.x.x) on Reh HAT 9.0. i was uninstall old version (Postgres 7.x.x) package with command rpm -e postgresqlxxxxx.rpm but only one package...
2
by: cacd1971 | last post by:
Hi, I use following C# code behind an aspx file to send a *.pdf file to the Internet Explorer. The variable "buffer" is of type byte and is filled with the contents of a *.pdf file. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.