+    // add remaining text to m_TextPieces:
+    if (end_pos - textBeginning > 0)
+        m_TextPieces->Add(
+            wxHtmlTextPiece(textBeginning, end_pos - textBeginning));
+}
+
+void wxHtmlParser::DestroyDOMTree()
+{
+    wxHtmlTag *t1, *t2;
+    t1 = m_Tags;
+    while (t1)
+    {
+        t2 = t1->GetNextSibling();
+        delete t1;
+        t1 = t2;
+    }
+    m_Tags = m_CurTag = NULL;
+
+    delete m_TextPieces;
+    m_TextPieces = NULL;
+}
+
+void wxHtmlParser::DoParsing()
+{
+    m_CurTag = m_Tags;
+    m_CurTextPiece = 0;
+    DoParsing(0, m_Source.Length());
+}
+
+void wxHtmlParser::DoParsing(int begin_pos, int end_pos)
+{
+    if (end_pos <= begin_pos) return;
+
+    wxHtmlTextPieces& pieces = *m_TextPieces;
+    size_t piecesCnt = pieces.GetCount();
+
+    while (begin_pos < end_pos)
+    {
+        while (m_CurTag && m_CurTag->GetBeginPos() < begin_pos)
+            m_CurTag = m_CurTag->GetNextTag();
+        while (m_CurTextPiece < piecesCnt &&
+               pieces[m_CurTextPiece].m_pos < begin_pos)
+            m_CurTextPiece++;
+
+        if (m_CurTextPiece < piecesCnt &&
+            (!m_CurTag ||
+             pieces[m_CurTextPiece].m_pos < m_CurTag->GetBeginPos()))
+        {
+            // Add text:
+            AddText(GetEntitiesParser()->Parse(
+                       m_Source.Mid(pieces[m_CurTextPiece].m_pos,
+                                    pieces[m_CurTextPiece].m_lng)));
+            begin_pos = pieces[m_CurTextPiece].m_pos +
+                        pieces[m_CurTextPiece].m_lng;
+            m_CurTextPiece++;
+        }
+        else if (m_CurTag)
+        {
+            // Add tag:
+            if (m_CurTag)
+            {
+                if (m_CurTag->HasEnding())
+                    begin_pos = m_CurTag->GetEndPos2();
+                else
+                    begin_pos = m_CurTag->GetBeginPos();
+            }
+            wxHtmlTag *t = m_CurTag;
+            m_CurTag = m_CurTag->GetNextTag();
+            AddTag(*t);
+            if (m_stopParsing)
+                return;
+        }
+        else break;