You are not able to access the SOM Element (XmlSchemaElement) from the
XmlValidatingReader. The new validating reader shipped in System.Xml in
Visual Studio 2005 beta1 does expose the SOM Element. You will have to
modify your code to work with this new validating reader.
In Visual Studio 2005 beta1, use the XmlSchemaSet class which is a
replacement for the XmlSchemaCollection. Below is a code sample to create
the reader and using it. At any point during validation, you can access the
SOM objects(XmlSchemaElement and XmlSchemaAttribute) from
vr.SchemaInfo.XmlSchemaElement
vr.SchemaInfo.XmlSchemaAttribute
Hope this helps,
-Zafar
Code Sample:
XmlReaderSettings settings = new XmlReaderSettings();
settings.XsdValidate = true;
settings.Schemas.ValidationEventHandler += new
ValidationEventHandler(ValidationCallback);
settings.ValidationEventHandler += new
ValidationEventHandler(ValidationCallback);
settings.Schemas.Add(null, "SCHEMA.XSD");
XmlReader vr = XmlReader.Create(xmlFile, null, new XmlUrlResolver(),
settings);
while(vr.Read()) {}
"Josh" <jo**@nautilusnet.com> wrote in message
news:38**************************@posting.google.c om...
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 upon
information contained within an XSD. Based on the selected element
within the Xml Instance document I want to find the corresponding
XmlSchemaElement in the XSD and then get parameters from the XSD to
customize the UI (min, max, allowable children, etc...).
Please help, I am driving myself nuts trying to figure out how to do
this. I thought I might be able to do it with the XmlValidatingReader
but it doesn't look like it will give me the XmlSchemaElement, just
the type....
THANK YOU FOR YOUR HELP, I NEED SLEEP!!!!! ;-)