There is a SchemaType property on the XmlValidatingRe ader which exposes the
XSD schema information of the SOM Element or Attribute currently being
validated in the XML Document. If your element is of a simple type with
certain facets, then while validating that element, you can access the
details of the schema facets this property.
for example: consider the XSD:
<xs:element name="root" type="rootType"/>
<xs:simpleTyp e name="rootType" >
<xs:restricti on base="xs:string ">
<xs:enumerati on value="a" />
</xs:restriction>
</xs:simpleType>
the following XML instance is invalid according to its facet in the schema.
<root>b</root>
while reading the document you can access the facets on the element like:
while (vr.Read())
{
if (vr.LocalName == "root" && vr.NodeType==Xm lNodeType.Eleme nt)
{
XmlSchemaSimple Type st = (XmlSchemaSimpl eType)vr.Schema Type;
XmlSchemaSimple TypeRestriction str =
(XmlSchemaSimpl eTypeRestrictio n)st.Content;
foreach (XmlSchemaObjec t obj in str.Facets)
{
Console.WriteLi ne(obj.ToString ());
}
}
}
if you are using the new validating XmlReaer (in Visual Studio 2005 beta1)
then the same property can be accessed via
reader.SchemaIn fo.SchemaType.
Hope this helps,
Zafar
"Matt" <md*****@sorviv e.DONT-SEND-SPAM.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
I know how to use the XmlReader to validate XML against a Schema but how
do I take this one step further and get the Facet information for an invalid
Xml element? I have my own validation event handler and I get the overall
message about the problem but I need to report on what exactly the problem
is. Does any know how to do this? Xml-Spy gives you the exact
information but I need to do it programmaticall y with customers data and report
errors. They want to know the exact error and right now I have to bring it into
Xml-Spy and create a manual report. .Net has got to have something to do
this!
Thanks,
Matt