用IHTMLElement, 可如何避免重复的节点呢?

解决方案 »

  1.   

    IHTMLElementCollection * pAnchors = NULL;
    if(SUCCEEDED(pDoc->get_all(&pAnchors)))
    {
    long imgcount = 0;
    if(SUCCEEDED(pAnchors->get_length(&imgcount)))
    {
    for(int i=0;i<imgcount;i++)
    {
    VARIANT index;
    VariantInit(&index);
    index.vt = VT_I4;
    index.intVal = i; IDispatch * pItem = NULL;
    pAnchors->item(index,index,&pItem);
    if(pItem != NULL)
    {
    // 对链接的数据检查
    IHTMLAnchorElement * pAnchorElement = NULL;
    if(SUCCEEDED(pItem->QueryInterface(IID_IHTMLAnchorElement,(void **)&pAnchorElement)))
    {
    CString hreftype;
    BSTR href,linktype;
    pAnchorElement->get_href(&href); //获取链接
    这样做,不会重复
      

  2.   

    Inserting an Element
    An element can be inserted into a document by calling the IMarkupServices::InsertElement method of the IMarkupServices interface. HRESULT InsertElement(
        IHTMLElement *pElementInsertThis,
        IMarkupPointer *pPointerStart,
        IMarkupPointer *pPointerFinish
    );
    The start pointer describes where the element is to come into scope, and the finish pointer specifies where it goes out of scope. The element to be inserted currently must not be in a document, and both pointers must be positioned in the same IMarkupContainer. For example, consider calling IMarkupServices::InsertElement on a b element with the following pointers: My [pstart]dog[pend] has fleas.
    They would produce a document with the following content:My [pstart]<B>dog[pend]</B> has fleas.
    Effectively, the start pointer is where the begin tag is placed, and the finish pointer is where the end tag is placed. Note that the pointers have left gravity, and position themselves to the left of the newly inserted content. If [pstart] were to have right gravity, the following would have resulted instead: My <B>[pstart]dog[pend]</B> has fleas.
    There is no restriction as to where a new element can be inserted. Thus, you can insert as many body elements as you want, or you can insert B elements into the head of the document. However, if the document were to be displayed or interacted with in such a state, the result would be undefined and is subject to change in Markup Services.