Ben Griffin wrote:
The following program outputs ( on cerr )

 >DOM Error:no declaration found for element 'tx'
 >DOM Error:attribute 'xmlns' is not declared for element 'tx'

I don't understand why.
What I would expect is for the namespace to be found, and then an error regarding that. Instead, there's a problem identifying that the xmlns declaration is a document identifier.

What am I doing wrong?


-------------------------------------------------
#include <iostream>

#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>

#include <xercesc/dom/DOMErrorHandler.hpp>
#include <xercesc/dom/DOMImplementationRegistry.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMImplementationLS.hpp>
#include <xercesc/dom/DOMLSParser.hpp>
#include <xercesc/dom/DOMLSInput.hpp>


using namespace xercesc;

class Err: public DOMErrorHandler {
public:
    bool Err::handleError(const xercesc::DOMError& domError) {
std::cerr << "DOM Error:" << (char *)(XMLString::transcode(domError.getMessage())) << "\r";
        return true;
    }
};

int main (int argc, char * const argv[]) {
    XMLPlatformUtils::Initialize();
    const XMLCh gLS[] = { 'L', 'S', chNull };
// <tx xmlns="http://bgriffin.net/tx"; />  but with no transocoder.
const XMLCh file[] = {'<','t','x',' ','x','m','l','n','s','=','"','h','t','t','p',':','/','/','b','g','r','i','f','f','i','n','.','n','e','t','/','t','x','"',' ','/','>',chNull}; DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(gLS); DOMLSParser* parser = ((DOMImplementationLS*)impl)->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0); DOMConfiguration* dc = parser->getDomConfig();
    Err* errHandler = new Err();
    dc->setParameter(XMLUni::fgDOMErrorHandler,errHandler);
    dc->setParameter(XMLUni::fgDOMValidate, true);
You're forcing the parser to validate your document, even though it has no grammar to use. As a result, it will report a validation error for every element in the document.

Dave

Reply via email to