[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xerces-c-users
Subject:    VALIDATION
From:       "bharath s" <bharaths1987 () gmail ! com>
Date:       2008-04-29 8:11:31
Message-ID: bc6e5f8d0804290059o4264de55g94d27a6f54a43960 () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi all,

       Im trying to validate an xml against a schema using Xerces 2.8 c++
parser..

Attachments:

schemafiles.rar contains all necessary .xsd files

xccdfnew.xml is the xml file im trying to validate.

valid.cpp is the code im using to validate the xml file..

Im able to validate it using oxygen XML editor which inturn uses xerces
library  only...


can u Plz review my code and let me know the necessary changes?


Thanks in advance,

Bharath Shankar

[Attachment #5 (text/html)]

<div>Hi all,</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Im trying to validate an xml against a \
schema using Xerces 2.8 c++ parser..</div> <div>&nbsp;</div>
<div>Attachments:</div>
<div>&nbsp;</div>
<div>schemafiles.rar contains all necessary .xsd files</div>
<div>&nbsp;</div>
<div>xccdfnew.xml is the xml file im trying to validate.</div>
<div>&nbsp;</div>
<div>valid.cpp is the code im using to validate the xml file..</div>
<div>&nbsp;</div>
<div>Im able to validate it using oxygen XML editor which inturn uses xerces \
library&nbsp; only...</div> <div>&nbsp;</div>
<div>&nbsp;</div>
<div>can u Plz review my code and let me know the necessary changes?</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>Thanks in advance,</div>
<div>&nbsp;</div>
<div>Bharath Shankar</div>
<div>&nbsp;</div>


["xccdfnew.xml" (text/xml)]

<?xml version="1.0" encoding="UTF-8"?>
<cdf:Benchmark xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://checklists.nist.gov/xccdf/1.1 \
../xccdf-1.1.3_xml-bundle_20070404/xccdf-1.1.xsd"  \
xmlns:dc="http://purl.org/dc/elements/1.1/"  \
xmlns:cpe="http://cpe.mitre.org/XMLSchema/cpe/1.0"  \
xmlns:htm="http://www.w3.org/1999/xhtml"  \
xmlns:cdf="http://checklists.nist.gov/xccdf/1.1"  id="aixpert-test-1"
 resolved="0"
 xml:lang="en">

   <cdf:status date="2008-02-04">draft</cdf:status>
   <cdf:title>XCCDF format for AIXpert</cdf:title>
<cdf:version>0.1.15</cdf:version>

   <cdf:Group id="PREREQ" selected="1" prohibitChanges="1">
      <cdf:title>Prereq rules</cdf:title>

      <cdf:description>This group indicates all The prerequisites that should exist \
in a target system</cdf:description>

         <cdf:Rule id="X11.Dt.ToolTalk" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l X11.Dt.ToolTalk</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="X11.Dt.bitmaps" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l X11.Dt.bitmaps</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="X11.Dt.lib" prohibitChanges="1" weight="1" >
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l X11.Dt.lib</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="X11.Dt.rte" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l X11.Dt.rte</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="X11.base.rte" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l X11.base.rte</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="bos.net.ipsec.keymgt" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l bos.net.ipsec.keymgt</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="bos.net.ipsec.rte" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l bos.net.ipsec.rte</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="bos.net.nfs.client" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l bos.net.nfs.client</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="bos.net.tcp.client" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l bos.net.tcp.client</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="bos.net.tcp.smit" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l bos.net.tcp.smit</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="bos.rte" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l bos.rte</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="bos.rte.ILS" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l bos.rte.ILS</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="bos.rte.SRC" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l bos.rte.SRC</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="bos.rte.commands" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l bos.rte.commands</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="bos.rte.control" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l bos.rte.control</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="bos.rte.date" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l bos.rte.date</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="bos.rte.install" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l bos.rte.install</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="bos.rte.methods" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l bos.rte.methods</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="bos.rte.odm" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l bos.rte.odm</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="bos.rte.security" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l bos.rte.security</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="bos.rte.shell" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l bos.rte.shell</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="prereqbinaudit" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l prereqbinaudit</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="prereqcde" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l prereqcde</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="prereqgated" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l prereqgated</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="prereqipsec" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l prereqipsec</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="prereqlft" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l prereqlft</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="prereqlh" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l prereqlh</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="prereqnontcb" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l prereqnontcb</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="prereqrl" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l prereqrl</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="prereqrrl" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l prereqrrl</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="prereqnosyn" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l prereqnosyn</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="prereqsed" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l prereqsed</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="prereqtcb" prohibitChanges="1" weight="1">
            <cdf:fixtext>The following command checks whether the required fileset is \
available or not</cdf:fixtext>

            <cdf:fix>lslpp -l prereqtcb</cdf:fix>
         </cdf:Rule>
      </cdf:Group>

<cdf:Group id="LLS" selected="1" prohibitChanges="1">
      <cdf:title>Low Level Security rules</cdf:title>

      <cdf:description>This group contains all rules related to Low Level Security \
organised into groups like "password policy","login policy"..etc</cdf:description>

      <cdf:Group id="LLS Password Policy Rules" selected="1" prohibitChanges="1">
         <cdf:title>Password policy rules</cdf:title>

         <cdf:description>This group contains all rules which enforce some specific \
setting related to password in a system..for ex:mininmum length of the password as \
per LLS</cdf:description>

         <cdf:Rule id="lls_maxage" prohibitChanges="1" weight="1">
            <cdf:title>Maximum age for password</cdf:title>

            <cdf:description>Specifies the maximum number of weeks (13 weeks) that a \
password is valid</cdf:description>

            <cdf:requires idref="bos.rte.date bos.rte.commands bos.rte.security \
bos.rte.shell bos.rte.ILS"/>

            <cdf:fixtext>Execute The script specified in fix to enforce the required \
settings</cdf:fixtext>

            <cdf:fix>chusrattr maxage=52 ALL lls_maxage</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="lls_maxexpired" prohibitChanges="1" weight="1">
            <cdf:title>Time to change password after the expiration</cdf:title>

            <cdf:description>Specifies the maximum number of weeks to 8 weeeks, after \
maxage that an expired password can be changed by the user</cdf:description>

            <cdf:requires idref="bos.rte.date bos.rte.commands bos.rte.security \
bos.rte.shell bos.rte.ILS"/>

            <cdf:fixtext>Execute The script specified in fix to enforce the required \
settings</cdf:fixtext>

            <cdf:fix>chusrattr maxexpired=8 ALL lls_maxexpired</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="lls_minlen" prohibitChanges="1" weight="1">
            <cdf:title>Minimum length for password</cdf:title>

            <cdf:description>Specifies the minimum length of a password to \
8</cdf:description>

            <cdf:requires idref="bos.rte.date bos.rte.commands bos.rte.security \
bos.rte.shell bos.rte.ILS"/>

            <cdf:fixtext>Execute The script specified in fix to enforce the required \
settings</cdf:fixtext>

            <cdf:fix>chusrattr minlen=8 ALL lls_minlen</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="lls_minalpha" prohibitChanges="1" weight="1">
            <cdf:title>Minimum number of alphabetic chars</cdf:title>

            <cdf:description>Specifies the minimum number of alphabetic characters in \
a password to 2</cdf:description>

            <cdf:requires idref="bos.rte.date bos.rte.commands bos.rte.security \
bos.rte.shell bos.rte.ILS"/>

            <cdf:fixtext>Execute The script specified in fix to enforce the required \
settings</cdf:fixtext>

            <cdf:fix>chusrattr minalpha=2 ALL lls_minalpha</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="lls_minother" prohibitChanges="1" weight="1">
            <cdf:title>Minimum number of non-alphabetic chars</cdf:title>

            <cdf:description>Specifies the minimum number of non-alphabetic \
characters in a password to 2</cdf:description>

            <cdf:requires idref="bos.rte.date bos.rte.commands bos.rte.security \
bos.rte.shell bos.rte.ILS"/>

            <cdf:fixtext>Execute The script specified in fix to enforce the required \
settings</cdf:fixtext>

            <cdf:fix>chusrattr minother=2 ALL lls_minother</cdf:fix>
         </cdf:Rule>

         <cdf:Rule id="lls_mindiff" prohibitChanges="1" weight="1">
            <cdf:title>Minimum number of chars</cdf:title>

            <cdf:description>Specifies the minimum number of characters required in a \
new password to 4, that were not in the old password</cdf:description>

            <cdf:requires idref="bos.rte.date bos.rte.commands bos.rte.security \
bos.rte.shell bos.rte.ILS"/>

            <cdf:fixtext>Execute The script specified in fix to enforce the required \
settings</cdf:fixtext>

            <cdf:fix>chusrattr mindiff=4 ALL lls_mindiff</cdf:fix>
         </cdf:Rule>
    </cdf:Group>

    <cdf:Group id="LLS User Group System and password definitions" selected="1" \
prohibitChanges="1">  <cdf:title>User Group System and password \
definitions</cdf:title>  <cdf:description>This group contains all rules which enforce \
some specific setting related to user group and system policies..for ex:"Check user \
Definitions" as per LLS</cdf:description>

		<cdf:Rule id="lls_tcbupdate" prohibitChanges="1" weight="1">
                        
					
						<cdf:title>TCB update</cdf:title>
						<cdf:description>Specifies the minimum number of characters required in a new \
                password to 4, that were not in the old password</cdf:description>
                        <cdf:requires idref="bos.rte.ILS bos.rte.shell \
                bos.rte.security bos.rte.commands"/>
                        <cdf:fixtext>Execute The script specified in fix to enforce \
the required settings</cdf:fixtext>  <cdf:fix>execmds "tcbck -y ALL"</cdf:fix>
        </cdf:Rule>

	</cdf:Group>	
</cdf:Group>
</cdf:Benchmark>


["valid.cpp" (text/plain)]

#include "xercesc/parsers/XercesDOMParser.hpp"
#include "xercesc/dom/DOM.hpp"
#include "xercesc/framework/StdOutFormatTarget.hpp"
#include "xercesc/framework/LocalFileFormatTarget.hpp"
#include <xercesc/sax/SAXException.hpp>
#include "xercesc/sax/HandlerBase.hpp"
#include "xercesc/util/XMLString.hpp"
#include <xercesc/util/XMLException.hpp>
#include "xercesc/util/PlatformUtils.hpp"
#include <xercesc/util/XercesDefs.hpp>
#include <errno.h>
#include <iostream>
using namespace std;
XERCES_CPP_NAMESPACE_USE


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(xercesc::XercesDOMParser::Val_Always);
        parser->setDoNamespaces(true); 
        parser->setDoSchema(true);
        parser->setSkipDTDValidation(true);
        ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();

        parser->setErrorHandler(errHandler);
     parser->setValidateAnnotations(true);
        parser->setExternalSchemaLocation(XMLString::transcode("http://checklists.nist.gov/xccdf/1.1 \
xccdf-1.1.xsd"));

char* xmlFile ="xccdfnew.xml" ;

        try {
            parser->parse(xmlFile);
        }
        catch (const XMLException& toCatch) {
            char* message = XMLString::transcode(toCatch.getMessage());


	cout << "Exception message is: \n"
                 << message << "\n";
 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;
        }
delete parser;
        //delete error;
        return 0;
    }



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic