You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Wade Smith <ws...@gmail.com> on 2010/01/14 20:32:07 UTC

How can I associate an xsd with an xml that has no xsd entry?

Hello,I have a validation routine that simply allows an xml file to be
validated against a supplied xsd.  In the event that the xml file has an xsd
entry, I have an entity resolver than points back to the supplied xsd.  That
portion is working fine.  I am also using the loadGrammar method with the
hopes of it using that xsd data since the namespace is the same as that in
the document.  If the document does not contain an xsd entry, it fails
validation on the root saying Unknown element.  Can anyone suggest a way
that I can associate the xsd properly?  The error handler and parser are
created outside the class and passed in. If more information is needed,
please let me know.

Environment:
Debian Linux running Xerces C++ 2.8

relevant code:

#include "validator.h"
#include <xercesc/framework/XMLSchemaDescription.hpp>

#include <xercesc/util/PlatformUtils.hpp>

#include <xercesc/dom/DOM.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMDocumentType.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMImplementationLS.hpp>
#include <xercesc/dom/DOMNodeIterator.hpp>
#include <xercesc/dom/DOMNodeList.hpp>
#include <xercesc/dom/DOMText.hpp>
#include <xercesc/util/XMLUni.hpp>

#include <xercesc/framework/LocalFileInputSource.hpp>
#include <xercesc/util/XMLString.hpp>





//
---------------------------------------------------------------------------
//  XMLValidator Class
//
---------------------------------------------------------------------------

//
---------------------------------------------------------------------------
//  XMLValidator Constructor
//
---------------------------------------------------------------------------
Internal::XMLValidator::XMLValidator(std::string activityFileName,
                    std::string xmlFileName,
                    xercesc::XercesDOMParser* parser,
                    UIIcon::ErrorObj* errorHandler,
                    bool forceNoNamespace) :
                XMLProcessorActivityFile(activityFileName,
                                   xmlFileName,
                                   parser,
                                   errorHandler){
}
//
---------------------------------------------------------------------------
//  XMLValidator: XMLValidator
//
---------------------------------------------------------------------------
// make validate force external and use the xsd specified
bool Internal::XMLValidator::process(){
    UIIcon::EntityResolver * entityResolver = NULL;
    try{
        // set the parser parameters

        entityResolver = new UIIcon::EntityResolver(_activityFileName);
        _parser->setXMLEntityResolver( entityResolver ) ;

        xercesc::LocalFileInputSource
schemaFile(DualString(_activityFileName).asXMLString());

        _parser->loadGrammar (schemaFile,
xercesc::Grammar::SchemaGrammarType, true);


        _parser->setValidationScheme( _parser->Val_Always ) ;

        _parser->setDoNamespaces( true ) ;
        _parser->setDoValidation( true );
        _parser->setDoSchema( false ) ;
        _parser->setValidationSchemaFullChecking( true );
        _parser->setValidationConstraintFatal(false);
        _parser->useScanner( xercesc::XMLString::transcode("SGXMLScanner"));


          // if not valid then return false.
          try{

_parser->parse(xercesc::XMLString::transcode(_sourceFileName.c_str()));
                // clear the memory used by the parser
                _parser->resetDocumentPool();
                // send the inverse of the error status since a succesfull
validation will have an error status of false
                return !_errorHandler->getErrorStatus();
          }
         // any exception means there was a problem other than validation so
rethrow
         catch(...){
             throw;
         }
    }
    // rethrow any raised errors
    catch (...){
        if (entityResolver != NULL){
            delete entityResolver;
        }
      throw;
    }

    return true;
  }

// end XMLValidator Class

Re: How can I associate an xsd with an xml that has no xsd entry?

Posted by Wade Smith <ws...@gmail.com>.
Thanks so much! That seems to have done it.

Wade

On Mon, Jan 18, 2010 at 10:54 AM, Boris Kolpackov
<bo...@codesynthesis.com>wrote:

> Hi,
>
> Vitaly Prapirny <ma...@mebius.net> writes:
>
> > Wade Smith wrote:
> > > do you have an example of how to call the setExternalSchemaLocation?
> > >I have not been able to get this working.
> >
> > _parser->setExternalSchemaLocation(
> >    "http://www.example.com file_name.xsd")
>
> The thing with setExternalSchemaLocation is that the schema path will be
> resolved relative to the XML file being parsed unless it is an absolute
> URI (in the file:/// form in case of a filesystem path). This page has
> some more information:
>
> http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/guide/#5.1
>
> Boris
>
> --
> Boris Kolpackov, Code Synthesis
> http://codesynthesis.com/~boris/blog
> Open-source <http://codesynthesis.com/%7Eboris/blog%0AOpen-source> XML
> data binding for C++   http://codesynthesis.com/products/xsd
> XML data binding for embedded systems
> http://codesynthesis.com/products/xsde
> Command line interface to C++ compiler
> http://codesynthesis.com/projects/cli
>

Re: How can I associate an xsd with an xml that has no xsd entry?

Posted by Wade Smith <ws...@gmail.com>.
Thanks for the reply Kelly.

An entity resolver works when there is an entry for an xsd.  I had
that part working as stated.  The problem I was running into was
sometimes it was stated and sometimes it just wasn't there (various
clients).  Using the method Boris and Vitaly outlined, I was able to
solve the problem.  I had tried to use it before but I was unsure of
the syntax and could not get it to work.

Wade

On Mon, Jan 18, 2010 at 10:59 AM, Kelly Beard <ke...@gmail.com> wrote:
>
> On Mon, Jan 18, 2010 at 9:54 AM, Boris Kolpackov
> <bo...@codesynthesis.com> wrote:
> > The thing with setExternalSchemaLocation is that the schema path will be
> > resolved relative to the XML file being parsed unless it is an absolute
> > URI (in the file:/// form in case of a filesystem path). This page has
> > some more information:
> >
> > http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/guide/#5.1
> >
> > Boris
>
> Yes, that was the problem I recently had.  I've successfully been able
> to load my own XSD by overriding an EntityResolver.  Seems to work for
> me.
>
> class RFIDResolver : public EntityResolver {
> public :
>    InputSource* resolveEntity(const XMLCh* const publicId, const
> XMLCh* const systemId)
>    {
>        CStr2XStr path("/home/dfcuser/rfid.xsd");
>
>        if (XMLString::compareString(systemId, path.unicodeForm())) {
>            return new LocalFileInputSource(path.unicodeForm());
>        } else {
>            return 0;
>        }
>    }
> };
>
> ...
>
>        RFIDResolver *rfidResolver = new RFIDResolver();
>        parser->setEntityResolver(rfidResolver);
>
> --
> Kelly Beard

Re: How can I associate an xsd with an xml that has no xsd entry?

Posted by Kelly Beard <ke...@gmail.com>.
On Mon, Jan 18, 2010 at 9:54 AM, Boris Kolpackov
<bo...@codesynthesis.com> wrote:
> The thing with setExternalSchemaLocation is that the schema path will be
> resolved relative to the XML file being parsed unless it is an absolute
> URI (in the file:/// form in case of a filesystem path). This page has
> some more information:
>
> http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/guide/#5.1
>
> Boris

Yes, that was the problem I recently had.  I've successfully been able
to load my own XSD by overriding an EntityResolver.  Seems to work for
me.

class RFIDResolver : public EntityResolver {
public :
    InputSource* resolveEntity(const XMLCh* const publicId, const
XMLCh* const systemId)
    {
        CStr2XStr path("/home/dfcuser/rfid.xsd");

        if (XMLString::compareString(systemId, path.unicodeForm())) {
            return new LocalFileInputSource(path.unicodeForm());
        } else {
            return 0;
        }
    }
};

...

        RFIDResolver *rfidResolver = new RFIDResolver();
        parser->setEntityResolver(rfidResolver);

-- 
Kelly Beard

Re: How can I associate an xsd with an xml that has no xsd entry?

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi,

Vitaly Prapirny <ma...@mebius.net> writes:

> Wade Smith wrote:
> > do you have an example of how to call the setExternalSchemaLocation?  
> >I have not been able to get this working.
>
> _parser->setExternalSchemaLocation(
>    "http://www.example.com file_name.xsd")

The thing with setExternalSchemaLocation is that the schema path will be
resolved relative to the XML file being parsed unless it is an absolute
URI (in the file:/// form in case of a filesystem path). This page has 
some more information:

http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/guide/#5.1

Boris

-- 
Boris Kolpackov, Code Synthesis        http://codesynthesis.com/~boris/blog
Open-source XML data binding for C++   http://codesynthesis.com/products/xsd
XML data binding for embedded systems  http://codesynthesis.com/products/xsde
Command line interface to C++ compiler http://codesynthesis.com/projects/cli

RE: Getting Xerces-C 3.0.1 to run on an HP-UX Itanium 64-bitmachine

Posted by "Dantzler, DeWayne C" <de...@boeing.com>.
Boris Kolpackov, wrote

>If you are using the pre-compiled binary from the Xerces-C++ website then you need to make sure you download the >64-bit version. If you built it yourself, see the build instructions on how to configure a 64-bit build on HP-UX/ia64:

>http://xerces.apache.org/xerces-c/build-3.html


Dantzler, DeWayne C <de...@boeing.com> writes:

>> I'm trying to get Xerces-c 3.0.1 to run on an HP-UX Itanium box. 
>> I was able to install it, but it crashes when I run it. I've included 
>> the stack trace( given below) and noticed a reference to a 32-bit 
>> version of HP-UX library(libCsup.so.1). There is a 64-bit version, so 
>> does Xerces need to run on an Itanium with the 64-bit version? If so, 
>> how do I re-configure xerces to use the 64-bit version?


Thanks Boris, this should help!!

Re: Getting Xerces-C 3.0.1 to run on an HP-UX Itanium 64-bit machine

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
DeWayne,

Dantzler, DeWayne C <de...@boeing.com> writes:

> I'm trying to get Xerces-c 3.0.1 to run on an HP-UX Itanium box. 
> I was able to install it, but it crashes when I run it. I've 
> included the stack trace( given below) and noticed a reference 
> to a 32-bit version of HP-UX library(libCsup.so.1). There is 
> a 64-bit version, so does Xerces need to run on an Itanium with 
> the 64-bit version? If so, how do I re-configure xerces to use 
> the 64-bit version?

If you are using the pre-compiled binary from the Xerces-C++ website
then you need to make sure you download the 64-bit version. If you
built it yourself, see the build instructions on how to configure
a 64-bit build on HP-UX/ia64:

http://xerces.apache.org/xerces-c/build-3.html

Boris

-- 
Boris Kolpackov, Code Synthesis        http://codesynthesis.com/~boris/blog
Open-source XML data binding for C++   http://codesynthesis.com/products/xsd
XML data binding for embedded systems  http://codesynthesis.com/products/xsde
Command line interface to C++ compiler http://codesynthesis.com/projects/cli

Getting Xerces-C 3.0.1 to run on an HP-UX Itanium 64-bit machine

Posted by "Dantzler, DeWayne C" <de...@boeing.com>.
Hello, Xerces-User's

I'm trying to get Xerces-c 3.0.1 to run on an HP-UX Itanium box. I was able to install it, but it crashes when I run it. I've included the stack trace( given below) and noticed a reference to a 32-bit version of HP-UX library(libCsup.so.1). There is a 64-bit version, so does Xerces need to run on an Itanium with the 64-bit version? If so, how do I re-configure xerces to use the 64-bit version?

0000074fda1d0:0 in free+0xb0 () from /usr/lib/hpux32/libc.so.1
#1  0x2000000073f703d0:0 in operator delete(void*)+0x50 () from /usr/lib/hpux32/libCsup.so.1
#2  0x20000000748c1050:0 in xercesc_3_0::MemoryManagerImpl::deallocate () at /net/sinai/home/d/dcd9420/labs/xercesLab/xerces-c-3.0.1/src/xercesc/internal/MemoryManagerImpl.cpp:53
#3  0x2000000074875eb0:0 in xercesc_3_0::IGXMLScanner::cleanUp () at /net/sinai/home/d/dcd9420/labs/xercesLab/xerces-c-3.0.1/src/xercesc/util/RefHashTableOf.c:229
#4  0x2000000074873480:0 in xercesc_3_0::IGXMLScanner::~IGXMLScanner () at /net/sinai/home/d/dcd9420/labs/xercesLab/xerces-c-3.0.1/src/xercesc/internal/IGXMLScanner.cpp:161
#5  0x2000000074a33270:0 in xercesc_3_0::AbstractDOMParser::~AbstractDOMParser () at /net/sinai/home/d/dcd9420/labs/xercesLab/xerces-c-3.0.1/src/xercesc/parsers/AbstractDOMParser.cpp:162
#6  0x2000000074a52950:0 in xercesc_3_0::AbstractDOMParser::~AbstractDOMParser () at /net/sinai/home/d/dcd9420/labs/xercesLab/xerces-c-3.0.1/src/xercesc/parsers/AbstractDOMParser.cpp:130
#7  0x2000000074a8b060:0 in xercesc_3_0::XercesDOMParser::~XercesDOMParser () at /net/sinai/home/d/dcd9420/labs/xercesLab/xerces-c-3.0.1/src/xercesc/parsers/XercesDOMParser.cpp:66
#8  0x415d580:0 in csCtkXmlDOMParser::~csCtkXmlDOMParse


Thanks 




Re: How can I associate an xsd with an xml that has no xsd entry?

Posted by Vitaly Prapirny <ma...@mebius.net>.
Wade Smith wrote:
> do you have an example of how to call the setExternalSchemaLocation?  I have
> not been able to get this working.

_parser->setExternalSchemaLocation(
    "http://www.example.com file_name.xsd")

Good luck!
	Vitaly

>
> On Fri, Jan 15, 2010 at 2:08 AM, Vitaly Prapirny<ma...@mebius.net>  wrote:
>
>> Wade Smith wrote:
>>
>>> If the document does not contain an xsd entry, it fails
>>> validation on the root saying Unknown element.  Can anyone suggest a way
>>> that I can associate the xsd properly?
>>>
>>
>> You should use setExternalSchemaLocation and
>> setExternalNoNamespaceSchemaLocation methods for this.
>>
>> Good luck!
>>         Vitaly
>>
>


Re: How can I associate an xsd with an xml that has no xsd entry?

Posted by Wade Smith <ws...@gmail.com>.
do you have an example of how to call the setExternalSchemaLocation?  I have
not been able to get this working.

On Fri, Jan 15, 2010 at 2:08 AM, Vitaly Prapirny <ma...@mebius.net> wrote:

> Wade Smith wrote:
>
>> If the document does not contain an xsd entry, it fails
>> validation on the root saying Unknown element.  Can anyone suggest a way
>> that I can associate the xsd properly?
>>
>
> You should use setExternalSchemaLocation and
> setExternalNoNamespaceSchemaLocation methods for this.
>
> Good luck!
>        Vitaly
>

Re: How can I associate an xsd with an xml that has no xsd entry?

Posted by Vitaly Prapirny <ma...@mebius.net>.
Wade Smith wrote:
> If the document does not contain an xsd entry, it fails
> validation on the root saying Unknown element.  Can anyone suggest a way
> that I can associate the xsd properly?

You should use setExternalSchemaLocation and 
setExternalNoNamespaceSchemaLocation methods for this.

Good luck!
	Vitaly