Pages: 1
Print
Author Topic: How to copy a node and insert it into a specific position  (Read 2374 times)
pooh2583
Member

Posts: 47


« on: February 18, 2013, 11:41:50 PM »

Hello,

I need to copy a specific node from an Xmetal document and insert the same node at a valid place in the same xml document,

ie
<Node att1="789" att2="78">
<child1 att1="45">g</child1>
</Node>

I wnt to copy this whole node which is present somewhere in the document and i want to paste/insert the same node at a plce

I need to have same contents in the new node as that of copied node.


please reply how to achieve this.

Regards
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2621



WWW
« Reply #1 on: February 19, 2013, 02:46:59 PM »

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. <Node> 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).
« Last Edit: February 19, 2013, 03:49:08 PM by Derek Read » Logged
pooh2583
Member

Posts: 47


« Reply #2 on: February 20, 2013, 01:45:45 AM »

Hello,

My xmetal Tree structure is as follows,

<Node1>
<A>
  <A1>
       <A11>
      <A111 att1="45" att2="'67>
              <A1111>data</A21>
      </A111>
   </A11>
   <A12>
       
   <A12>
 </A1>

</A>

</Node1>


Now i want to copy entire element named A111 including attributes and nodes into A12

i have got the node using ActiveDocument.getNodesByXPath I just need to copy this node and insert into node named A12

even I am able to select the node A12

I just want to know how to copy the entire node and insert it into the specified node.


Logged
Pages: 1
Print
Jump to:  

email us