cancel
Showing results for 
Search instead for 
Did you mean: 

accessing node with in a node

Former Member
0 Kudos

Hello

I have a situation in which a Model Parent Node has 2 Model child node one with the cardinality 0..1 (Singletond true)and the other with the cardinality 0..n (Singleton true).

I need to copy this Model Node elements to the value node elements having the same structure. i.e., the Value node also has two child value nodes one with the cardinality 0..1 and the other 0..n .

Please can any body help in with a sample code or tutorial for accessing the structures and copying the nodes and also adding the new elements to these nodes.

Vinay

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Vinay,

Try this for copying (if structure are same between 2 trees):

import com.sap.tc.webdynpro.progmodel.api.WDCopyService;
...
WDCopyService.copySubtree(nodeFrom, nodeTo);

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com

Former Member
0 Kudos

Hello Valery,

I tried using copySubTree , still it did not copy the child nodes to the value context.

After executing WDCopyService.copySubTree(modelNode,valueNode). The code I used was

for(int i=0; i < wdContext.nodeValueNode().size; i++)

{

wdContext.valueNode.setLeadSelection(i);

wdContext.currentValueNodeElement.node().getChildNode("childnode",wdContext.valueNode.getLeadSelection());

At this point I found that the childNode size is 0 .

So there child node was not copied.

Please can you specify the proper method with which I can copy the Model node elements to the value node elements

Thanks in advance,

V Vinay

Former Member
0 Kudos

Vinay,

First, I said that you can use copySubTree only if structures are the same.

Second, I've noticed in your origina post, that your target node (valueNode) has singleton children. Make them non-singletons.

VS

Former Member
0 Kudos

Hello Vinay,

here is the code to traverse recursive dynamically a node.


void traverseNode(IWDNode node) {        
    IWDNodeInfo nodeInfo = node.getNodeInfo();
    //Every element
    for (int i = 0; i < node.size(); i++) {
        IWDNodeElement nodeElement = 
             node.getElementAt(i);
        Iterator attributeInfoIterator =   
             nodeInfo.iterateAttributes();
        //Every Attribute
        while (attributeInfoIterator.hasNext()) {
            IWDAttributeInfo attributeInfo =
         (IWDAttributeInfo) attributeInfoIterator.next();
            String name = attributeInfo.getName();
            try {
                Object value = 
                  nodeElement.getAttributeValue(name);
                //Do something with the value
            }
            catch (ContextException ignored){}
        }
    }
    //Every child node
    Iterator nodeInfoIterator =  
        nodeInfo.iterateChildren();
    while (nodeInfoIterator.hasNext()) {
        IWDNodeInfo childNodeInfo = (IWDNodeInfo) 
            nodeInfoIterator.next();
        IWDNode childNode =node.getChildNode(
            childNodeInfo.getName(),
            IWDNode.LEAD_SELECTION);
        //recursive call
        traverseNode(childNode);
    }
}

Hope ist helps.

Best regards,

Matthias

Former Member
0 Kudos

Hi Vinay,

Like you have Model structure:

Model1

|__model11 (0..1)

|__model12 (0..n)

Your Value node structure:

value1

|__value11 (0..1)

|__value12 (0..n)

I assume that you have singleton property of the value node value12 is true.

Write following code to copy all the elements:

ele1 = wdcontext.nodeValue1().createValue1Element();

wdcontext.nodeValue1().bind(ele1);

ele11 = wdcontext.nodeValue11().createValue11Element();

//copy values of attribute from model to value node attributes...

ele11.setAtrr1(wdcontext.currentModel11Element().getAttr1());

wdcontext.nodeValue11().bind(ele11);

wdcontext.nodeModel12().moveFirst();

for(int i=0; i<wdcontext.nodeModel12().size();i++)

{

ele12 = wdcontext.nodeValue12().createValue12Element();

//copy values of attribute from model to value node attributes...

ele12.setAtrr12(wdcontext.currentModel21Element().getAttr12());

wdcontext.nodeValue12().addElement(ele12);

wdcontext.nodeModel12().moveNext();

}

Regards,

Bhavik