473,587 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can i get the corresponding Schemaelement from a Validationerror

Hallo,

i have to validate many XML's Documents with a XSD. Some XML's throw a Validationerror like "The 'type' attribute has an invalid value according to its data type".
To produce automatically a valid XML i would need the corresponding Schemaelement, to get the Defaultvalue for that Attribute.

Can anybody help me?
From http://www.developmentnow.com/g/49_0...dotnet-xml.htm

Posted via DevelopmentNow. com Groups
http://www.developmentnow.com
Nov 12 '05 #1
3 1731


Willi wrote:

i have to validate many XML's Documents with a XSD. Some XML's throw
a Validationerror like "The 'type' attribute has an invalid value
according to its data type". To produce automatically a valid XML i
would need the corresponding Schemaelement, to get the Defaultvalue
for that Attribute.


The ValidationEvent Args has a property named Exception of type
XmlSchemaExcept ion which has members like SourceSchemaObj ect leading to
schema information.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
Hallo

Thanks for your Help, but the SourceSchemaObj ect always returns null.
What's wrong here? I wrote a little Testapp for demonstration:

using System;
using System.Xml;
using System.Xml.Sche ma;
using System.Diagnost ics;
namespace ConsoleApplicat ion1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
Class1 c = new Class1();
c.ValidationTes t();
}
public void ValidationTest( )
{
try
{
string schematext = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
";
schematext += "<xs:schema
xmlns:xs=\"http ://www.w3.org/2001/XMLSchema\"
elementFormDefa ult=\"qualified \">";
schematext += "<xs:elemen t name=\"document \"> ";
schematext += "<xs:complexTyp e> ";
schematext += "<xs:attrib ute name=\"type\" type=\"xs:strin g\"
use=\"required\ "/>";
schematext += "</xs:complexType> ";
schematext += "</xs:element>";
schematext += "</xs:schema>";

XmlNamespaceMan ager nsmgr = new XmlNamespaceMan ager(new
NameTable());
XmlParserContex t context = new XmlParserContex t(null, nsmgr, null,
XmlSpace.None);
XmlTextReader tr = new
XmlTextReader(s chematext,XmlNo deType.Document ,context);
XmlSchema schema = XmlSchema.Read( tr,new
ValidationEvent Handler(this.Sc hemaValidationE vent));
schema.Compile( new ValidationEvent Handler(this.Co mpileEvent));
if (schema.IsCompi led)
{
string sXML = "<document type=\"\"></document>";
XmlValidatingRe ader reader = new XmlValidatingRe ader(sXML,
XmlNodeType.Doc ument, context);
reader.Validati onEventHandler += new
ValidationEvent Handler(this.Xm lValidationEven t);
reader.Schemas. Add(schema);
while (reader.Read()) {}
}
}
catch (Exception e)
{
Debug.WriteLine (e.Message + " " + e.StackTrace);
}
}
private void SchemaValidatio nEvent (object sender, ValidationEvent Args
args)
{
Debug.WriteLine ("Schema Validation Error: " + args.Message);
if (args.Exception .SourceSchemaOb ject != null)
{
Debug.WriteLine (args.Exception .SourceSchemaOb ject.SourceUri) ;
}
}
private void CompileEvent (object sender, ValidationEvent Args args)
{
Debug.WriteLine ("Schema Compile Error: " + args.Message);
if (args.Exception .SourceSchemaOb ject != null)
{
Debug.WriteLine (args.Exception .SourceSchemaOb ject.SourceUri) ;
}
}
private void XmlValidationEv ent (object sender, ValidationEvent Args
args)
{
Debug.WriteLine ("XML Validation Error: " + args.Message);
if (args.Exception .SourceSchemaOb ject != null)
{
Debug.WriteLine (args.Exception .SourceSchemaOb ject.SourceUri) ;
}
}

}
}
Thanks for your Help in advance
--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 12 '05 #3
Sorry i frogot to remove the type Attribute to demonstrate the
Behaviour.

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 12 '05 #4

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

Similar topics

3
1422
by: Augustus | last post by:
Hiya! I have a question: I have 2 tables... "Inventory" and "Price" These tables are used by 2 restaurants... the inventory has what they sell, and prices has the corresponding prices to those items for each location. What I want to do:
4
7641
by: Jim in Arizona | last post by:
This doesn't make any sense to me. I'm hoping some SQL guru out there knows the answer. I'm making a help desk type database system. There's only two tables, one called TTickets and the other called TNotes. The Primay Key of TTickets is a one to Many to the Foreign Key of the TNotes table. In my VB code, I create a relation between the two tables so I can display several notes (from TNotes) with a single entry in the TTickets table. So...
3
1187
by: aburayan | last post by:
Having a SQL table contains many columns. One of them contains integers of corresponding descriptions;i.e 1 for ready, 2 for done .... And i read the values and display the corresponding item list. How to do that? Thanks indeed.
10
4939
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than the column order of the datatable). I also allow the user to click on a column header to sort the datagrid by that column. I need to identify the row and column in the datatable when the user clicks on a cell in the datagrid. Using the...
3
3147
by: technocraze | last post by:
Hi community experts, May I knw whether is it possible to display the corresponding value of the second textbox based on the user input in the first textbox? This means that once the user enters the value of first textbox - S1, the corresponding matching value based on first textbox will be displayed in the second textbox automatically. I have tried using the AfterUpdate() event of textbox1 control to trigger this scenario but doesnt seem...
2
2508
by: technocraze | last post by:
Hi community experts, I am encountering a problem to display the corresponding values of the combo box into the textboxes. I have chose option 1 & 3 for this implementation but neither is working. My combo box only contains distinct values, once i select the values frm that combo box, the corresponding matching the values from the combo box from the table will be displayed in the textboxes. It wont make much sense if I bound the textboxes to...
1
4331
by: roveagh1 | last post by:
Hi I've been using the 2 year old link below to repeat values from previous record field into current corresponding field. It's worked fine for text but the last piece of advice was to use the same logic for a date field. i.e. theValue.defaultvalue = "#" & theValue.value & "#" I can't get this to work for some reason and I can't figure out why. Can anyone out there help? Thanks Repeat value of previous record field into current...
4
2743
by: padmapriya | last post by:
I need to create three radio buttons and when the radio button is clicked, the corresponding text fields such as 3 different address types should get activated. If i clicked the first radio button, the text field corresponding to that should be enabled and the other two address type fields should be disabled. This is working fine for the first radio button. But for the other two radio buttons also, the first address type field only gets...
0
7857
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
8352
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...
1
7981
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6632
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...
1
5723
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3846
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...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2367
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
0
1194
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.