공장 이야기

Webkit에서 HTML Tag를 문자열로 입력 받았을 때 IDOMElement 바꾸는 방법

바다가소주라면- 2012. 7. 16. 16:24

아래에서 this는 Document* 이다.


PassRefPtr<Element> Document::createHTMLTagElement(const String& html)

{

    unsigned uLoop = 0;

    Node* pChildNode = NULL;

    unsigned uBodyChild = 0;

    Node* nodeBodyChild = NULL;

    unsigned uLoopBody = 0;

    bool bFindParse = false;


    if(0 >= html.length())

        return 0;


    RefPtr<DocumentFragment> fragment = DocumentFragment::create(this);

    if(NULL == fragment)

        return NULL;

    fragment->parseHTML(html, this->documentElement());


    unsigned uChildNodeCount = fragment->childNodeCount();

    for(uLoop=0; uLoop<uChildNodeCount; uLoop++)

    {

        pChildNode = fragment->childNode(uLoop);

        if(NULL == pChildNode)

            continue;

        if(true == pChildNode->hasTagName(QualifiedName(nullAtom, "body", xhtmlNamespaceURI)))

        {

            uBodyChild = pChildNode->childNodeCount();

            for(uLoopBody=0; uLoopBody<uBodyChild; uLoopBody++)

            {

                nodeBodyChild = pChildNode->childNode(uLoopBody);

                bFindParse = true;

                break;

            }

        }

    }

    if(false == bFindParse)

        return NULL;


    RefPtr<Element> htmlElement(static_cast<Element*>(nodeBodyChild));

    

    return htmlElement.release();

}