Exemple #1
0
bool XMLHandler::endElement(const QString & /*namespaceURI*/, const QString & /*localName*/, const QString & /*qName*/)
{
    if(currentNode()->nodeType() == Node::TEXT_NODE)
        exitText();

    NodeImpl *node = popNode();
    if(node)
    {
        node->close();
        while(currentNode() && currentNode()->implicitNode()) // for the implicit HTMLTableSectionElementImpl
            popNode()->close();
    }
    else
        return false;

    return true;
}
Exemple #2
0
void XMLTokenizer::finish()
{
    m_source.setFinished(true);
    if(!m_noErrors)
    {
        // An error occurred during parsing of the code. Display an error page to the user (the DOM
        // tree is created manually and includes an excerpt from the code where the error is located)

        // ### for multiple error messages, display the code for each (can this happen?)

        // Clear the document
        int exceptioncode = 0;
        while(m_doc->hasChildNodes())
            static_cast< NodeImpl * >(m_doc)->removeChild(m_doc->firstChild(), exceptioncode);

        QString line, errorLocPtr;
        if(m_handler.errorLine)
        {
            QString xmlCode = m_source.data();
            QTextIStream stream(&xmlCode);
            for(unsigned long lineno = 0; lineno < m_handler.errorLine - 1; lineno++)
                stream.readLine();
            line = stream.readLine();

            for(unsigned long colno = 0; colno < m_handler.errorCol - 1; colno++)
                errorLocPtr += " ";
            errorLocPtr += "^";
        }

        // Create elements for display
        DocumentImpl *doc = m_doc;
        NodeImpl *html = doc->createElementNS(XHTML_NAMESPACE, "html");
        NodeImpl *body = doc->createElementNS(XHTML_NAMESPACE, "body");
        NodeImpl *h1 = doc->createElementNS(XHTML_NAMESPACE, "h1");
        NodeImpl *headingText = doc->createTextNode(i18n("XML parsing error"));
        NodeImpl *errorText = doc->createTextNode(m_handler.errorProtocol());
        NodeImpl *hr = 0;
        NodeImpl *pre = 0;
        NodeImpl *lineText = 0;
        NodeImpl *errorLocText = 0;
        if(!line.isNull())
        {
            hr = doc->createElementNS(XHTML_NAMESPACE, "hr");
            pre = doc->createElementNS(XHTML_NAMESPACE, "pre");
            lineText = doc->createTextNode(line + "\n");
            errorLocText = doc->createTextNode(errorLocPtr);
        }

        // Construct DOM tree. We ignore exceptions as we assume they will not be thrown here (due to the
        // fact we are using a known tag set)
        doc->appendChild(html, exceptioncode);
        html->appendChild(body, exceptioncode);
        if(body)
            body->appendChild(h1, exceptioncode);
        h1->appendChild(headingText, exceptioncode);
        body->appendChild(errorText, exceptioncode);
        body->appendChild(hr, exceptioncode);
        body->appendChild(pre, exceptioncode);
        if(pre)
        {
            pre->appendChild(lineText, exceptioncode);
            pre->appendChild(errorLocText, exceptioncode);
        }

        // Close the renderers so that they update their display correctly
        // ### this should not be necessary, but requires changes in the rendering code...
        h1->close();
        if(pre)
            pre->close();
        body->close();

        m_doc->recalcStyle(NodeImpl::Inherit);
        m_doc->updateRendering();

        end();
    }
    else
    {
        // Parsing was successful. Now locate all html <script> tags in the document and execute them
        // one by one
        addScripts(m_doc);
        m_scriptsIt = new QPtrListIterator< HTMLScriptElementImpl >(m_scripts);
        executeScripts();
    }
}