There is a SchemaType property on the XmlValidatingReader 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:simpleType name="rootType">
<xs:restriction base="xs:string">
<xs:enumeration 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==XmlNodeType.Element)
{
XmlSchemaSimpleType st = (XmlSchemaSimpleType)vr.SchemaType;
XmlSchemaSimpleTypeRestriction str =
(XmlSchemaSimpleTypeRestriction)st.Content;
foreach (XmlSchemaObject obj in str.Facets)
{
Console.WriteLine(obj.ToString());
}
}
}
if you are using the new validating XmlReaer (in Visual Studio 2005 beta1)
then the same property can be accessed via
reader.SchemaInfo.SchemaType.
Hope this helps,
Zafar
"Matt" <md*****@sorvive.DONT-SEND-SPAM.com> wrote in message
news:%2****************@tk2msftngp13.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 programmatically 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