471,347 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Problem with .NET Beta2 upgrade, with XSD traversal (LocalElements issue!!) ...Please help

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

Jul 21 '05 #1
0 1095

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Nevets Steprock | last post: by

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.