AllExperts > Experts 
Search      

XML

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More XML Answers
Question Library

Ask a question about XML
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Ashvin
Expertise
I can handle all the queries related to XML. I can sort out problems regarding XSLT and XSL. I work using MSXML components. I can handle XML-SQl, XML-VB and XMl-ASP related queries.

Experience
I have worked for 2years in this feild. I have worked in SGML and DTDs, and now working in XML and Schemas.

 
   

You are here:  Experts > Computing/Technology > HTML/XML > XML > validating an XML schema - Xerces

Topic: XML



Expert: Ashvin
Date: 6/8/2004
Subject: validating an XML schema - Xerces

Question
My daughter (recent college grad) is working on a web site for a non profit and has no "senior person" available to assist her when she gets stumped.  She's working with XML/XERCES trying to validate a schema.... would you know how to help with this?


Answer
Hello carol binkoeski,

You have to tell me the language you are using to integrate xerces. well I am sending you the code for C++ parser

<!--Code-->
  #include <xercesc/parsers/XercesDOMParser.hpp>
   #include <xercesc/dom/DOM.hpp>
   #include <xercesc/sax/HandlerBase.hpp>
   #include <xercesc/util/XMLString.hpp>
   #include <xercesc/util/PlatformUtils.hpp>

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

       try {
           XMLPlatformUtils::Initialize();
       }
       catch (const XMLException& toCatch) {
           char* message = XMLString::transcode(toCatch.getMessage());
           cout << "Error during initialization! :\n"
                << message << "\n";
           XMLString::release(&message);
           return 1;
       }

       XercesDOMParser* parser = new XercesDOMParser();
       parser->setValidationScheme(XercesDOMParser::Val_Always);    // optional.
       parser->setDoNamespaces(true);    // optional

       ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
       parser->setErrorHandler(errHandler);

       char* xmlFile = "x1.xml";

       try {
           parser->parse(xmlFile);
       }
       catch (const XMLException& toCatch) {
           char* message = XMLString::transcode(toCatch.getMessage());
           cout << "Exception message is: \n"
                << message << "\n";
           XMLString::release(&message);
           return -1;
       }
       catch (const DOMException& toCatch) {
           char* message = XMLString::transcode(toCatch.msg);
           cout << "Exception message is: \n"
                << message << "\n";
           XMLString::release(&message);
           return -1;
       }
       catch (...) {
           cout << "Unexpected Exception \n" ;
           return -1;
       }

       delete parser;
       delete errHandler;
       return 0;
   }
         
Feel free to contact me.

I am online at Hotmail and Yahoo from 9:30 to 5:30 Indian standard time.

ashvinJohnson@hotmail.com
ashvinMax@yahoo.com


Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.