473,387 Members | 1,925 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,387 software developers and data experts.

validating XML against XSD using XercesC++

1
Hi All,
i m using the following code for validation but it terminates with this message---
"terminate called after throwing an instance of 'xercesc_2_7::DOMException'
Aborted"

#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/parsers/AbstractDOMParser.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMImplementationLS.hpp>
#include <xercesc/dom/DOMImplementationRegistry.hpp>
#include <xercesc/dom/DOMBuilder.hpp>
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMNodeList.hpp>
#include <xercesc/dom/DOMError.hpp>
#include <xercesc/dom/DOMLocator.hpp>
#include <xercesc/dom/DOMNamedNodeMap.hpp>
#include <xercesc/dom/DOMAttr.hpp>

#include <string.h>
#include <stdlib.h>
#include <xercesc/dom/DOMErrorHandler.hpp>
#include <xercesc/util/XMLString.hpp>
#include "DOMCount.hpp" //for my error handlers

#if defined(XERCES_NEW_IOSTREAMS)
#include <iostream>
#else
#include <iostream.h>
#endif


XERCES_CPP_NAMESPACE_USE


int main(int argc, char* argv[])
{

try
{
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch)
{
//strGeneralResult.Format(_T("Error during Xerces initialization! :\n%s\n"), toCatch.getMessage());
return -1;
}

static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };

DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(gL S);
DOMBuilder* parser = ((DOMImplementationLS*)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHR ONOUS, 0);

parser->setFeature(XMLUni::fgDOMNamespaces, true);
parser->setFeature(XMLUni::fgXercesSchema, true);
parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true);

parser->setFeature(XMLUni::fgDOMValidation, true);

// enable datatype normalization - default is off
parser->setFeature(XMLUni::fgDOMDatatypeNormalization, true);

XMLCh* propertyValue = XMLString::transcode(argv[1]);
parser->setFeature(XMLUni::fgXercesSchemaExternalNoNameSp aceSchemaLocation,propertyValue);

// And create our error handler and install it
// CMyDOMErrorHandler must be derived from DOMErrorHandler
DOMCountErrorHandler* errorHandler;
parser->setErrorHandler(errorHandler);

//
// Get the starting time and kick off the parse of the indicated
// file. Catch any exceptions that might propogate out of it.
//
unsigned long duration;

XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* doc = 0;

try
{
// reset document pool
parser->resetDocumentPool();
char* filename = argv[2];
doc = parser->parseURI(filename);
}
catch (const XMLException& toCatch)
{
XERCES_STD_QUALIFIER cout<<"\nhere1\n";
//strGeneralResult.Format(_T("Error during parsing: %s\nXMLException message is:\n %s\n"), strXMLFile, toCatch.getMessage());
}
catch (const DOMException& toCatch)
{
XERCES_STD_QUALIFIER cout<<"\nhere2\n";
const unsigned int maxChars = 2047;
XMLCh errText[maxChars + 1];

//strGeneralResult.Format(_T("DOM Error during parsing:%s\nDOMException code is: %d\n"), strXMLFile, toCatch.code);

if (DOMImplementation::loadDOMExceptionMsg(toCatch.co de,errText, maxChars))
{
//CString strDOMExc;
//strDOMExc.Format(_T("\nMessage is: %s"), errText);

//strGeneralResult +=strDOMExc;
}
}
catch (...)
{
XERCES_STD_QUALIFIER cout<<"\nhere3\n";
//strGeneralResult.Format(_T("Unexpected exception during parsing: %s\n"), strXMLFile);
}

XMLPlatformUtils::Terminate();
return 0;
}

i saw some postings here regarding validation and tried to use those codes but still its not working for me :(
Any help to resolve this issue is highly appreciated.

Thanks in advance
dees
Sep 17 '07 #1
1 2767
Dököll
2,364 Expert 2GB
It's likely you've seen this: http://mail.pm.org/pipermail/melbour...er/002097.html
Sep 19 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: H.L Bai | last post by:
hi, everybody i meet a parse error when i used the xml4c. any proposal is helpful. The error is following .../XMLRegionHandler.h:59 parse error before '*' .../XMLRegionHandler.h:60 parse...
1
by: davisjoseph | last post by:
Hi All, I'm using Xerces C++ 2.50 DOM version for Validating a valid XML againt the Schema(XSD) available; But it always shows an error in XSD I suppose; This is the error I'm getting using...
30
by: Toni Mcintyre | last post by:
i'm having 2 problems with the http://validator.w3.org 1. if i have: <meta http-equiv="Content-Script-Type" content="text/javascript"> then why do i need <script type=text/javascript>...
6
by: Iain | last post by:
I've got a system which takes an XML file, translates it into an update gram and then loads it into my database with SQLXML3 (all in dot net). But it's fragile. And the SQLXML 3 error reporting...
1
by: Christian | last post by:
Hi, I load an Xml-file "customers.xml" into a DataSet (works fine) but then how do I validate it against a schema (e.g. customers.xsd) ? my customers.xml: <?xml version="1.0"...
3
by: Shailendra Batham | last post by:
hi guys I need your suggestions / opinion for doing this the right way. I have a XML and a Schema for the same What I want is when its validated against the schema, it should give custom...
1
by: Cesar | last post by:
Hello, I've developed a .NET C# web service; which has one method named, let's say, upload_your_data. This method has one parameter ( string your_data). The value that this parameter will...
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...
4
by: agda.karlberg | last post by:
Hello, I need to remove the DTD reference from an xml document, the reason for this is that we want to validate against a schema instead (which we have locally). It takes up to a minute to fetch...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.