General XMetaL Discussion
XMetaL Community Forum › General XMetaL Discussion › How to determine the end of the document?
-
biswajitsr May 4, 2010 at 5:57 am
How to determine the end of the document?
May 4, 2010 at 5:57 amParticipants 2Replies 3Last Activity 12 years, 10 months agoI am using range object to traverse the document and paste a certain string withing the document. I am using the movedown method fo that purpose.
Derek Read May 4, 2010 at 6:07 pm
Reply to: How to determine the end of the document?
May 4, 2010 at 6:07 pmI think we need a more information.
One way to get to the end the document using only Range is as follows. The Select() is added so you can see where you end up.
[code]rng = ActiveDocument.Range;
rng.MoveToDocumentStart();
rng.SelectContainerContents();
rng.Collapse(sqCollapseEnd);
rng.Select();[/code]This gets you there as well:
[code]docNode = ActiveDocument.documentElement;
rng = ActiveDocument.Range;
rng.SelectAfterNode(docNode);
rng.Select();[/code]Or this:
[code]rng = ActiveDocument.Range;
rng.MoveToDocumentEnd();
rng.Select();[/code]There are probably many other ways. Are these even close to what you are doing?
biswajitsr May 5, 2010 at 5:35 am
Reply to: How to determine the end of the document?
May 5, 2010 at 5:35 amI am using range object to traverse the document and paste a certain string withing the document. I am using the movedown method for that purpose. But I am thinking when traversing if end of the document reached then null exception may occur. So is there any way to know when reached to end of the document?
Derek Read May 5, 2010 at 6:49 pm
Reply to: How to determine the end of the document?
May 5, 2010 at 6:49 pmHow about checking inside your loop to see if the current node, Range.ContainerNode is equal to ActiveDocument.documentElement.
When that check returns true then jump out of the loop (if your scripting language provides that mechanism) or use the equivalent of “while not” in your scripting language for the type of loop.
-
AuthorPosts
- You must be logged in to reply to this topic.