473,811 Members | 3,521 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with XML-Validation

I have got an XML file, that aderes to a XDR-Schema which references
elements and attributes in two other XDR-Schemas.
I want to validate this XML file before I create a DOM tree in C#. This
works fine for every namespace except of the default namespace. In the
default namespace there is no Event when the XML file is wrong.

Could anybody tell me what there is wrong with my code (as seen below)? I
have tried several things, but I could not make the validation work
properly.
The class simply creates a DOM form a XML file and writes every error out in
the console.

Best regards,

Daniel Haag

public class XmlVerify
{
bool m_documentValid = true;
string m_path = @"C:\FDT XML Schemas\";
string m_filename;
/// <summary>
/// Validates an XML file with its schema.
/// </summary>
/// <param name="stream">S tream to the XmlFile</param>
/// <param name="schemapat h">Directory with schema files</param>
/// <returns>XmlDoc ument</returns>
public XmlDocument ValidateXml(str ing filename,string schemapath)
{
m_filename = filename;
XmlValidatingRe ader valReader=null;
XmlDocument doc=null;
try
{
// Create ValidatingReade r
valReader = new
XmlValidatingRe ader(stream,Xml NodeType.Docume nt,null);
// Append EventHandler
valReader.Valid ationEventHandl er +=new
System.Xml.Sche ma.ValidationEv entHandler(valR eader_Validatio nEventHandler);
// Set Validation Type
valReader.Valid ationType = ValidationType. XDR;
// Add Schemas to Collection if XDR is not Referenced in XML
XmlSchemaCollec tion schemaCollectio n =
GetSchemaCollec tion(schemapath );
// Add SchemaCollectio n to Validtaingreade r's Schema property
valReader.Schem as.Add(schemaCo llection);
doc= new XmlDocument(val Reader.NameTabl e);
// Parse XmlData
doc.Load(valRea der);
}
catch (XmlException e)
{
Console.WriteLi ne(e.Message);
}
finally
{
if (valReader!=nul l)
{
// Close Stream
valReader.Close ();
}
}
// Return document
if (m_documentVali d)
{
Console.WriteLi ne("Document valid:\t{0}", m_filename);
return doc;
}
else
{
Console.WriteLi ne("Document invalid:\t{0}", m_filename);
m_documentValid =true;
return null;
}
}
// -------------------------------------------------------------------------
----------------
/// <summary>
/// Returns a XmlSchemaCollec tion for all xdr schemas in the directory.
/// </summary>
/// <param name="directoy" >Path to the schema files</param>
/// <returns>Schema s</returns>
public XmlSchemaCollec tion GetSchemaCollec tion(string directoy)
{
// instantiate SchemaCollectio n
XmlSchemaCollec tion schemas = new XmlSchemaCollec tion();
string [] fileEntries = System.IO.Direc tory.GetFiles(d irectoy, "*.xml");
foreach(string file in fileEntries)
{
// Set Validation EventHandler
schemas.Validat ionEventHandler +=new
ValidationEvent Handler(Schema_ ValidationEvent Handler);
// Get namespace
FileInfo fileinfo = new FileInfo(file);
string namespaceString = "x-schema:"+filein fo.Name;
// Add schema to schemacollectio n
schemas.Add(nam espaceString,fi leinfo.FullName );
}
return schemas;
}
private void valReader_Valid ationEventHandl er(object sender,
System.Xml.Sche ma.ValidationEv entArgs e)
{
// 3. Write handling code
Console.WriteLi ne("DocumuentVa lidation{0}:\n{ 1}",e.Severity, e.Message);
m_documentValid = false;
}
private void Schema_Validati onEventHandler( object sender,
System.Xml.Sche ma.ValidationEv entArgs e)
{
// 5.3 Write handling code
Console.WriteLi ne("SchemaValid ation{0}:\n{1}" ,e.Severity, e.Message);
}
}
Nov 12 '05 #1
0 1382

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

Similar topics

4
5400
by: jesper | last post by:
Hi I am currently following the tutorial from IBM (http://www-106.ibm.com/developerworks/xml/edu/x-dw-xjaxb-i.html) I have three problems at the moment. 1. It says else where that when the source code files are generated using the XJC, it is possible to compile the generated source code using javac generated\*.java generated\impl\*.java , but this only gives me 97 errors.?
2
3412
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only happening when I put my XML files and the .xsl files on my ISP's system for my home page. If I try to open the XML files in Netscape 7.0 on my own machine (ie, not on the ISP's system), the pages convert file and the result is displayed in HTML.
2
9931
by: Dale Gerdemann | last post by:
I'm having trouble with Unicode encoding in DOM. As a simple example, I read in a UTF-8 encoded xml file such as: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <aText>letter 'a' with umlaut: ä</aText> And when I serialize it, it comes out encoded as ISO-8895-1. But I don't think the problem is with serialization. In processing my XML files, I'm matching bits and pieces of text and attributes with some
5
10085
by: Alexis | last post by:
Hello, I have a set of classes I created from schema files using the xsd.exe tool. I'm using namespaces in the clases ( I had to because I have some classes with the same name but not the same class ) Here is how a given class wil looks like. <System.Xml.Serialization.XmlRootAttribute(:="mynamespace", IsNullable:=False)> _ Public Class ClassName
7
2872
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID parameter to the XSLT stylesheet XsltArgumentList xsltArgList = new XsltArgumentList(); xsltArgList.AddParam("pmID", "", pmID); xmlItems.TransformArgumentList = xsltArgList;
0
912
by: ZippyV | last post by:
Hello everybody, I'm trying to convert a given xsd scheme to vb.net code with the help of xsd.exe. I've had no problems during conversion but the problem is that I can't build the code in vs.net. I keep getting the error: "Reference to a non-shared object requires an object reference". The weird thing is that this problem doesn't occur in every Class in that vb-file. I don't have a clue how to fix this problem. Here is one of the...
16
4932
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by Microsoft must be installed on their servers. Now german Umlaute (ä, ü, ö) and quotes are returned incorrectly in SOAP fault responses. This can be easily verified: Implement the following in a web service method (just raises a SOAPException with a...
4
3265
by: Jean-François Michaud | last post by:
Hello, I've been looking at this for a bit now and I don't see what's wrong with the code. Can anybody see a problem with this? Here is an XSLT snippet I use. <xsl:template match="graphic"> <xsl:param name="path" /> <fo:block padding-after="12pt">
3
9587
by: Jon L | last post by:
Hi, I'm hoping someone can help me with this problem. I'm not sure whether the problem lies with the software or with my understanding of the language. I'm using the Microsoft.XMLDOM object in an ASP page to read an incoming XML post request and respond to it. Although the XMLDOM object verifies the XML at a basic level, I want to make sure that the request is in the correct format (as per the specification I have to
3
2656
by: John Carlyle-Clarke | last post by:
Hi. I'm new to Python and trying to use it to solve a specific problem. I have an XML file in which I need to locate a specific text node and replace the contents with some other text. The text in question is actually about 70k of base64 encoded data. I wrote some code that works on my Linux box using xml.dom.minidom, but it will not run on the windows box that I really need it on. Python 2.5.1 on both.
0
9726
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10647
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...
1
10395
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
10130
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
9204
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
7667
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
5553
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...
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
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.