Home Forums General XMetaL Discussion How to copy a node and insert it into a specific position Reply To: How to copy a node and insert it into a specific position

Derek Read

Reply to: How to copy a node and insert it into a specific position

Please describe the exact steps your code needs to perform so I can try to write an example.

Something like this:
1) Select the current element. If not the current element then how do we find it? Look for the first/second/third/etc. element? Look for an attribute value? Specific content?
2) Copy the whole node. How? To the clipboard? By duplicating it without modifying the clipboard?
3) It sort of sounds like you want to modify what was copied. If so, what is changing exactly?
4) Move the insertion point (cursor) after some other element. What criteria do we use to find the element (name, location)?
5) Insert what was copied (and possibly modified).
6) etc…

APIs to look at in the Programmers Guide include:
Range.ContainerNode
Range.SelectContainerContents()
Range.SelectElement()
Range.ContainerNode.Xml
Range.Text
Range.TextWithRM
Range.PasteString()
Range.PasteStringAsText()
Range.PasteStringWithInterpret()

…and all of the various Range methods related to moving around the document.

You can also do this with the DOM APIs. However, DOM is a more difficult concept to grasp (especially for people just beginning to write macros) so I would avoid using it unless you have some very specific need (it will be rare to find something you cannot do with Range/Selection that you can only do with DOM).

Reply

Products
Downloads
Support