On Apr 5, 9:27 am, Boris Zbarsky <[EMAIL PROTECTED]> wrote:
> krithika wrote:
> > I am actually trying to insert comments at certain points to indicate
> > page breaks.
>
> I suggest setting a range at the point where you want to insert the comment 
> and
> using the range operations to insert a node at that point....  That will 
> handle
> splitting text nodes as needed, etc.
>
> -Boris

Hi,

I tried your suggestion as shown

// create comment as shown
nsAutoString str,comment,value;
comment.Assign(NS_LITERAL_STRING("<!-- MY COMMENT -->"));
nsCOMPtr<nsIContent> text;
NS_NewCommentNode(getter_AddRefs(text),nsnull);
nsCOMPtr<nsIDOMNode> commentNode = do_QueryInterface(text);


                        nsCOMPtr<nsIDOMDocument> doc;
                        node->GetOwnerDocument(getter_AddRefs(doc));
                        nsCOMPtr<nsIDOMDocumentRange>
docRange(do_QueryInterface(doc));
                        if (docRange)
                        {
                                nsCOMPtr<nsIDOMRange> range;
                                docRange-
>CreateRange(getter_AddRefs(range));
                                if (range)
                                {
                                    range->SelectNode(node);
                                    nsCOMPtr<nsIDOMText> newtext;
                                    //doc-
>CreateTextNode(comment,getter_AddRefs(newtext));
                                    //range->InsertNode(newtext);
                                    range->InsertNode(commentNode);

                                }
                        }

Both InsertNode(newtext) and InsertNode(commentNode) gives me the same
result.
I get &lt; MY COMMENT &gt; and not <!-- MY COMMENT -- > as expected.

How do I overcome this?

regards,
Krithika

_______________________________________________
dev-tech-layout mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-layout

Reply via email to