You have full access to what's called the SOM (Schema Object Model). That
includes knowing if an element is a simple or complex type, its particles
(i.e. child elements), etc.
The Items/Elements/Attributes will only give you those items that are
defined globally, NOT those that are local elements, which is quite common
and, IMO, a better design practice if the elements/types are not going to be
reused anywhere else.
The easiest way is to get first the top-level elements through the .Elements
property. Here's how to iterate:
foreach (DictionaryEntr y entry in schema.Elements )
{
if (entry.Value is XmlSchemaElemen t)
{
//We have an element
}
}
Next, you can query its type (to see if they have a complexType definition)
and keep going to list the children. This is done as follows (requires a
recursive function to be effective, actually, but you get the idea):
XmlSchemaElemen t rootelement = (XmlSchemaEleme nt) entry.Value;
if (rootelement.Sc hemaType is XmlSchemaComple xType)
{
XmlSchemaComple xType roottype =
(XmlSchemaCompl exType)rootelem ent.SchemaType;
// Check for a sequence child element (particle content model). May be a
choice too, for example.
if (roottype.Parti cle is XmlSchemaSequen ce)
{
XmlSchemaSequen ce rootseq = (XmlSchemaSeque nce) roottype.Partic le;
foreach (Dictionary innerentry in rootseq.Items)
{
if (entry.Value is XmlSchemaElemen t)
{
//Recurse forever ;)
}
}
}
}
--
.../dcazz
Daniel Cazzulino
DEVerest - Lagash
Tel +54 (0) 11 4247 7396
www.deverest.com.ar www.lagash.com
dotnetopensrc.s ourceforge.net
Coauthor of:
Beginning C# Web Applications with Visual Studio .NET
Beginning Web Programming using VB.NET and Visual Studio .NET
Professional ASP.NET Server Controls: Building Custom Controls with C#
ASP.NET Components Toolkit
"He who is good for making excuses, is seldom good for anything else."
"Cy Huckaba" <ru******@t-3.com> wrote in message
news:e0******** ******@tk2msftn gp13.phx.gbl...
OK, at least I'm not going crazy.
If I put an xpath navigator on it Can I cast the nodes I want into
XMLSchema Elements so I can have access to datatypes, etc?
I'll give it a shot...thanks for the reply.
Cy
"MSFT" <lu******@onlin e.microsoft.com > wrote in message
news:cE******** ******@cpmsftng xa06.phx.gbl... Hi Austin,
From XMLSchema object's property, we can only get the inforamtion about
namespace and SourceUri. However, XSD file is also a text file in XML
format. I think you can read it as a common XML file with XMLTextReader
and list all elements nodes in the textbox.
Luke
"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026?? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
http://www.microsoft.com/security/se...s/ms03-026.asp and/or
to visit Windows Update at http://windowsupdate.microsoft.com to install
the patch. Running the SCAN program from the Windows Update site will help
to insure you are current with all security patches, not just MS03-026."