473,386 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Xml Validation Against Schema Facets

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
Nov 12 '05 #1
3 2331


Matt wrote:
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!


Your validation event handler is passed an argument with a property
Exception of type XmlSchemaException, if the properties you find there
don't give you the information you are looking for then I don't think
..NET exposes them.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #2
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

Nov 12 '05 #3
Zafar,

Thanks for the information, this is exactly what I am looking for!

Matt

"Zafar Abbas [MSFT]" <za****@microsoft.com> wrote in message
news:#U**************@TK2MSFTNGP11.phx.gbl...
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


Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Olaf Meyer | last post by:
Apprentently xerces 2.6.0 (Java) does not validate against contraints specified in the schema (e.g. constraints specified via unique element). The validation works with the XML editor I'm using...
2
by: Sudip Chakraborty | last post by:
Is there a way to see constraint validation errors while loading xml into a DataSet ? I'm interested in the line number in the xml file which is causing the error. I've enclosed the relevant stack...
1
by: eXavier | last post by:
Hi, I need to validate XML fragment against XSD schema. The main issue is that xml fragment does not contain refrence to schema, but I want to force the validation against the schema I have in...
2
by: Shone | last post by:
I would like to perform a 2-pass XML reading from a stream. Once using the Validating reader, just to confirm the validity against the schema, and next time to do a reading to extract the data....
3
by: Dave | last post by:
Hi, I'm really confused as to how to validate XML fragments against a schema in C#. I am creating XML through an automated process and have an .xsd which was given to me to validate against....
5
by: paul_zaoldyeck | last post by:
does anyone know how to validate an xml file against multiple defined schema? can you show me some examples? i'm making here an xml reader.. thank you
7
by: christian.eickhoff | last post by:
Hi Everyone, I am currently implementing an XercesDOMParser to parse an XML file and to validate this file against its XSD Schema file which are both located on my local HD drive. For this...
6
by: lists | last post by:
Hi all, I am trying to validate an XML file against an XSD schema file within a ..NET C++ program, but the validation doesn't seem to be occuring. My code is listed below. The validation...
9
by: mstilli | last post by:
Hi, I am trying to use schema for server side validation using xerces to catch the validation errors. validating this XML: <Content4> <textarea13></textarea13>...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.