xerces-c-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Xanadu <xanadu.mich...@googlemail.com>
Subject Whitespace - I'm going slighty mad!
Date Wed, 09 Sep 2009 17:02:56 GMT
I tryed to use Xerces 3 to read a xml file and I'm going slightly mad. I
have no problem to get the first node of my xml file, but xerces always
returns "#text" when I want to get its child node. I think the problem has
something to do with the so-called "whitespace". I tryed everything (dtd,
set features) without sucess. Please help and take a look at my code. I'm
under pressure. :-( (my xml file and dtd are in the attachement)

Regards, Michael




    XMLCh tempStr[100];
    XMLString::transcode("LS", tempStr, 99);
    DOMImplementation *impl =
DOMImplementationRegistry::getDOMImplementation(tempStr);
    DOMLSParser* parser =
((DOMImplementationLS*)impl)->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS,
0);

    char* dtdFile = "d://projects//personal.dtd";
    parser->loadGrammar(dtdFile, Grammar::DTDGrammarType, true);

    // optionally you can set some features on this builder
    if (parser->getDomConfig()->canSetParameter(XMLUni::fgDOMValidate,
true))
        parser->getDomConfig()->setParameter(XMLUni::fgDOMValidate, true);
    if (parser->getDomConfig()->canSetParameter(XMLUni::fgDOMNamespaces,
true))
        parser->getDomConfig()->setParameter(XMLUni::fgDOMNamespaces, true);
    if
(parser->getDomConfig()->canSetParameter(XMLUni::fgDOMDatatypeNormalization,
false))

parser->getDomConfig()->setParameter(XMLUni::fgDOMDatatypeNormalization,
false);

    //here I messed aroung with some features without sucess
    //parser->getDomConfig()->setParameter(XMLUni::fgXercesSchema, true );

//parser->getDomConfig()->setParameter(XMLUni::fgXercesSchemaFullChecking,
true );

//parser->getDomConfig()->setParameter(XMLUni::fgDOMElementContentWhitespace,
false);
    //parser->getDomConfig()->setParameter(XMLUni::fgXercesLoadExternalDTD,
true);
    //parser->getDomConfig()->setParameter(XMLUni::fgXercesLoadSchema, true
);

//parser->getDomConfig()->setParameter(XMLUni::fgXercesUseCachedGrammarInParse,
true);

    ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
    parser->getDomConfig()->setParameter(XMLUni::fgDOMErrorHandler,
errHandler);

    char* xmlFile = "d://projects//personal.xml";
    xercesc_3_0::DOMDocument *doc = 0;

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

    DOMElement *root = doc->getDocumentElement();
    DOMNode* node = root->getFirstChild();
    const XMLCh* ch = node->getNodeName();    //here I just get "#text"

    parser->release();

Mime
View raw message