本文整理汇总了C++中NodeImpl::appendChild方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeImpl::appendChild方法的具体用法?C++ NodeImpl::appendChild怎么用?C++ NodeImpl::appendChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeImpl
的用法示例。
在下文中一共展示了NodeImpl::appendChild方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleResidualStyleCloseTagAcrossBlocks
void KHTMLParser::handleResidualStyleCloseTagAcrossBlocks(HTMLStackElem* elem)
{
// Find the element that crosses over to a higher level. For now, if there is more than
// one, we will just give up and not attempt any sort of correction. It's highly unlikely that
// there will be more than one, since <p> tags aren't allowed to be nested.
int exceptionCode = 0;
HTMLStackElem* curr = blockStack;
HTMLStackElem* maxElem = 0;
HTMLStackElem* prev = 0;
HTMLStackElem* prevMaxElem = 0;
while (curr && curr != elem) {
if (curr->level > elem->level) {
if (maxElem)
return;
maxElem = curr;
prevMaxElem = prev;
}
prev = curr;
curr = curr->next;
}
if (!curr || !maxElem || !isAffectedByResidualStyle(maxElem->id)) return;
NodeImpl* residualElem = prev->node;
NodeImpl* blockElem = prevMaxElem ? prevMaxElem->node : current;
NodeImpl* parentElem = elem->node;
// Check to see if the reparenting that is going to occur is allowed according to the DOM.
// FIXME: We should either always allow it or perform an additional fixup instead of
// just bailing here.
// Example: <p><font><center>blah</font></center></p> isn't doing a fixup right now.
if (!parentElem->childAllowed(blockElem))
return;
if (maxElem->node->parentNode() != elem->node) {
// Walk the stack and remove any elements that aren't residual style tags. These
// are basically just being closed up. Example:
// <font><span>Moo<p>Goo</font></p>.
// In the above example, the <span> doesn't need to be reopened. It can just close.
HTMLStackElem* currElem = maxElem->next;
HTMLStackElem* prevElem = maxElem;
while (currElem != elem) {
HTMLStackElem* nextElem = currElem->next;
if (!isResidualStyleTag(currElem->id)) {
prevElem->next = nextElem;
prevElem->node = currElem->node;
delete currElem;
}
else
prevElem = currElem;
currElem = nextElem;
}
// We have to reopen residual tags in between maxElem and elem. An example of this case is:
// <font><i>Moo<p>Foo</font>.
// In this case, we need to transform the part before the <p> into:
// <font><i>Moo</i></font><i>
// so that the <i> will remain open. This involves the modification of elements
// in the block stack.
// This will also affect how we ultimately reparent the block, since we want it to end up
// under the reopened residual tags (e.g., the <i> in the above example.)
NodeImpl* prevNode = 0;
NodeImpl* currNode = 0;
currElem = maxElem;
while (currElem->node != residualElem) {
if (isResidualStyleTag(currElem->node->id())) {
// Create a clone of this element.
currNode = currElem->node->cloneNode(false);
// Change the stack element's node to point to the clone.
currElem->node = currNode;
// Attach the previous node as a child of this new node.
if (prevNode)
currNode->appendChild(prevNode, exceptionCode);
else // The new parent for the block element is going to be the innermost clone.
parentElem = currNode;
prevNode = currNode;
}
currElem = currElem->next;
}
// Now append the chain of new residual style elements if one exists.
if (prevNode)
elem->node->appendChild(prevNode, exceptionCode);
}
// We need to make a clone of |residualElem| and place it just inside |blockElem|.
// All content of |blockElem| is reparented to be under this clone. We then
// reparent |blockElem| using real DOM calls so that attachment/detachment will
// be performed to fix up the rendering tree.
// So for this example: <b>...<p>Foo</b>Goo</p>
// The end result will be: <b>...</b><p><b>Foo</b>Goo</p>
//
// Step 1: Remove |blockElem| from its parent, doing a batch detach of all the kids.
blockElem->parentNode()->removeChild(blockElem, exceptionCode);
//.........这里部分代码省略.........
示例2: finish
void XMLTokenizer::finish()
{
// parse xml file
XMLHandler handler(m_doc,m_view);
QXmlInputSource source;
source.setData(m_xmlCode);
QXmlSimpleReader reader;
reader.setContentHandler( &handler );
reader.setLexicalHandler( &handler );
reader.setErrorHandler( &handler );
reader.setDeclHandler( &handler );
reader.setDTDHandler( &handler );
bool ok = reader.parse( source );
// ### handle exceptions inserting nodes
if (!ok) {
kdDebug(6036) << "Error during XML parsing: " << handler.errorProtocol() << endl;
int exceptioncode;
while (m_doc->hasChildNodes())
static_cast<NodeImpl*>(m_doc)->removeChild(m_doc->firstChild(),exceptioncode);
// construct a HTML page giving the error message
// ### for multiple error messages, display the code for each
QTextIStream stream(&m_xmlCode);
unsigned long lineno;
for (lineno = 0; lineno < handler.errorLine-1; lineno++)
stream.readLine();
QString line = stream.readLine();
m_doc->appendChild(m_doc->createElementNS("http://www.w3.org/1999/xhtml","html"),exceptioncode);
NodeImpl *body = m_doc->createElementNS("http://www.w3.org/1999/xhtml","body");
m_doc->firstChild()->appendChild(body,exceptioncode);
NodeImpl *h1 = m_doc->createElementNS("http://www.w3.org/1999/xhtml","h1");
body->appendChild(h1,exceptioncode);
h1->appendChild(m_doc->createTextNode(i18n("XML parsing error")),exceptioncode);
h1->renderer()->close();
body->appendChild(m_doc->createTextNode(handler.errorProtocol()),exceptioncode);
body->appendChild(m_doc->createElementNS("http://www.w3.org/1999/xhtml","hr"),exceptioncode);
NodeImpl *pre = m_doc->createElementNS("http://www.w3.org/1999/xhtml","pre");
body->appendChild(pre,exceptioncode);
pre->appendChild(m_doc->createTextNode(line+"\n"),exceptioncode);
unsigned long colno;
QString indent = "";
for (colno = 0; colno < handler.errorCol-1; colno++)
indent += " ";
pre->appendChild(m_doc->createTextNode(indent+"^"),exceptioncode);
pre->renderer()->close();
body->renderer()->close();
m_doc->applyChanges();
m_doc->updateRendering();
end();
}
else {
addScripts(m_doc);
m_scriptsIt = new QListIterator<HTMLScriptElementImpl>(m_scripts);
executeScripts();
}
}
示例3: finish
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();
}
}