Hi All,

            Sorry to have you critique my code but I’m not sure whether what I’m doing is right and I need your help. Is this construction and usage of my class (which inherits from DOMInputSource) correct? (aDOMParser is a DOMBuilder)

 

const char * cStringDOMInputSource::encoding = "ISO-8859-1";

 

 

std::string prologue =     "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<mrx:mrx xmlns:mrx=\""

                                                                                     "http://www.monitorplus.com/MRX\" xmlns:xsi=\""

                                                                                     "http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\""

                                                                           "http://www.monitorplus.com/MRX file:///umi/data/MonPlus/etc/schemas/mrx.xsd\">\n"

                                                                                     "<dummy/>\n",

                                                                           "</mrx:mrx>";

 

                        cStringDOMInputSource * ssdis = new cStringDOMInputSource(prologue);

                        try {

                                    aTmpDoc = aDOMParser->parse(*ssdis);

                        }

                        catch (const XMLException& toCatch) {

                                    char * message = XMLString::transcode(toCatch.getMessage());

                                    cReporter::Report(cReporter::Error,"MPXMLDataFile %s:XMLError during parsing of XML for prologue/epilogue to be inserted, %s",aXMLFileName,message);

                                    XMLString::release(&message);

                                    cMPXMLError err;

                                    err.setError(cMPXMLError::XMLException_Error,"",message);

                                    throw err;

                        }

                        catch (const DOMException& toCatch) {

                                    char * message = XMLString::transcode(toCatch.msg);

                                    cReporter::Report(cReporter::Error,"MPXMLDataFile %s:DOMError during parsing of XML for prologue/epilogue to be inserted, %s",aXMLFileName,message);

                                    XMLString::release(&message);

                                    cMPXMLError err;

                                    err.setError(cMPXMLError::DOMException_Error,"",message);

                                    throw err;

                        }

                        catch (...) {

                                    cReporter::Report(cReporter::Error,"MPXMLDataFile %s:Unknown exception thrown while parsing XML for prologue/epilogue to be inserted",aXMLFileName);

                                    cMPXMLError err;

                                    err.setError(cMPXMLError::UnknownException_Error);

                                    throw err;

                        }

 

 

class cStringDOMInputSource : public DOMInputSource

{

public:

            cStringDOMInputSource(string &ss);

            virtual ~cStringDOMInputSource() {}

 

            static const char * encoding;

 

            virtual const XMLCh* getEncoding() const {return aEncoding;}

            virtual const XMLCh* getPublicId() const {return 0;}

            virtual const XMLCh* getSystemId() const {return 0;}

            virtual const XMLCh* getBaseURI() const {return 0;}

 

            virtual void setEncoding(const XMLCh* const encodingStr)

                        {}

            virtual void setPublicId(const XMLCh* const publicId) {}

            virtual void setSystemId(const XMLCh* const systemId) {}

            virtual void setBaseURI(const XMLCh* const baseURI) {}

 

            virtual BinInputStream* makeStream() const  {return aBmis;}

            virtual void setIssueFatalErrorIfNotFound(const bool flag) {}

            virtual const bool getIssueFatalErrorIfNotFound() const {return false;}

            virtual void              release() {}

 

private:

            BinMemInputStream * aBmis;

            XMLCh* aEncoding;

};

 

inline

cStringDOMInputSource::cStringDOMInputSource(string &ss)

: aEncoding(new XMLCh[100])

{

            const char * const temppp = ss.c_str();

            const unsigned char * const uctemppp = reinterpret_cast<const unsigned char* const>(temppp);

            aBmis = new BinMemInputStream(uctemppp,ss.size());   

            XMLString::transcode(encoding,aEncoding,99);

}

 

 

Thanks a lot!

Bret Clark

Reply via email to