473,796 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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


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 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!


Your validation event handler is passed an argument with a property
Exception of type XmlSchemaExcept ion, 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 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

Nov 12 '05 #3
Zafar,

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

Matt

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


Nov 12 '05 #4

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

Similar topics

2
4661
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 (XMLSpy4) but not with Xerces 2.6.0. I've included a really short and simple example to illustrate it. I would like to get some comments on the validation capabilities of Xerces 2.6.0. I though it *fully* supported W3C Schema!
2
5188
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 trace below. at System.Data.DataSet.FailedEnableConstraints() at System.Data.DataSet.EnableConstraints() at System.Data.DataSet.set_EnforceConstraints(Boolean value)
1
2064
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 XmlSchema object. The scenario is as follows: I have string fragment;
2
9453
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. Actually, second time I do a deserialization, the data from XML is fed directly to an object. The problem I am experiencing is the error at the second reading attempt, and error description implies that reader is winded to the end of the XML and...
3
7421
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. Can someone give me some clue as to how to validate my XML string against this schema document? Is there some great secret that I'm missing?
5
4954
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
10291
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 purpose I set the corresponding XercesDOMParser feature as shown in the upcoming subsection of my code. As far as I understand, the parsing process should throw an DOMException in case the XML file doesn't match the Schema file (e.g. Element...
6
2736
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 event handler is not called even when the XML should valid properly against the schema. Obviously I'm missing something. Can anyone help?
9
3021
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> <binaryobject3></binaryobject3>
0
9533
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10461
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10239
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10019
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9057
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6796
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4122
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.