473,803 Members | 4,139 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Schema validation using Xerces-C++ version 1.6.0?

Hi y'all,

I am trying to do validation of xml files against their schema using
the Xerces library. I am expecting to get an exception while calling
DOMParser::pars e method when the xml file is invalid, i.e. it doesn't
conform to its schema, but I don't get any exception. What am I doing
wrong?

Following is snippet of my code:

------------------------------------------------------------------------------
int main(int argc, char* argv[])
{
try {
XMLPlatformUtil s::Initialize() ;
}
catch (const XMLException& toCatch) {
cout << "Error during initialization! :\n"
<< DOMString(toCat ch.getMessage() ) << endl;
return 1;
}

string xml_file = "test.xml";
bool valid = true;

try
{
DOMParser* parser = new DOMParser;

parser->setDoNamespace s(true);
parser->setDoSchema(tr ue);
parser->setValidationS chemaFullChecki ng(true);
parser->setValidationC onstraintFatal( true);
ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
parser->setErrorHandle r(errHandler);

parser->parse(xml_file .c_str());

delete errHandler;
delete parser;
}
catch (...) {
cout << "An error occurred during parsing" << endl;
valid = false;
}

cout << "The xml file is " << ( valid ? "valid" : "invalid" ) <<
endl;

XMLPlatformUtil s::Terminate();

return 0;
}

------------------------------------------------------------------------------
Thank you for your replies.

Vikas
Jul 20 '05 #1
0 1542

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

Similar topics

3
3332
by: Robert Lintner | last post by:
Hi, I woult like to switch from DTD to XML-Schema and am looking for an equivalent to external ENTITY for composition of an xml file from modules --- my.dtd -- <?xml version="1.0" encoding="ISO-8859-1"?> <!ENTITY module1 SYSTEM "module1.xml"> <!ENTITY module2 SYSTEM "module2.xml"> .....
1
3667
by: Ole Hedegaard | last post by:
Hi, I've been looking into the Xerces documentation, and to my surprise it seems that it is impossible to validate an XML document againts an XML Schema without having a schemaLocation (or noNameSpaceSchemaLocation) reference in the XML document. I basically just want to validate some "foreign" XML, which I did not generate myself, against my own Schemas. Is that really impossible with Xerces, or am I missing something?
1
1604
by: Duncan Smith | last post by:
Hello All, Has anyone found a way to specify an xsd schema programatically when using the apache xerces xml processor? I know that the validation works fine as long as the xml instance document explicitly refernces the schema via an 'xsd:xsi schemaLocation=...' tab. But how can you validate xml documents which don't contain the schemaLocation? Reading the instance and assigning the schemaLocation before flushing it back out and...
3
3782
by: D. Alvarado | last post by:
Hello, I am sort of new to all this XML, but I would like to enforce a date format within one of my XML elements. Everything I've read indicates that a DTD is not suitable for this purposes, so I should use a schema. In as far as this seems to be the only limitation of a DTD, are there any disadvantages to using a schema? Or should I just use a DTD and have a little extra programming to verify valid date formats (which seems to defeat...
4
5611
by: joes | last post by:
Hello there I tried for several days to get a simple validation with xml schema & xerces working. Goal for me is tuse JAXP and not specific Xerces classes. I don't get the point what I am doing wrong. Could somebody help me? I didn't find any full example working on the net. Thank you for any hints! If I run the examples below, the parsers parses the file well, no vlaidation is occuring although the schema and xml file does not
0
1743
by: motoman | last post by:
I have a problem with the code sample below, basically when i run it i get the error classnotfoundexception org.apache.xerces.parsers.SAXParser now i know the simple answer is declare xerces.jar in your classpath but i have done that. I have even gotten xerces 2.5...... and still nothing, i am really struggling here. see the code below.
1
1749
by: mrc-1 | last post by:
Hello, I built a XSD File with the tool XML-Spy from Altova. My XML file consists of about 5000 elements. If I use the validate button in XML-Spy, the validation process takes about 8 seconds. But if I use Xerces-J2 to validate my XML File it takes about 90 seconds (xerces-c takes about 85 sec). Does anybody know, why xerces is that slow resp. why XML Spy is that fast?
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...
1
4750
by: Nuno | last post by:
Hello, I'm looking for a way of validating/parsing the xsd file (schema), i only been able of validating the xml file with the corresponding schema, but what i want is only validate the xsd file, to check if the schema is valid. I'm using Xerces-C++ and the only thing that i found is a way of parsing the xml file with the xml schema like this:
9
3023
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
9699
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
9562
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
10309
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
6840
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
5496
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
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4274
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
2
3795
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2968
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.