I happed to find the solution myself on this. Apparently the only thing that i had to do was
a) Get the required "Profile" node object
b) Seperate out the "Lanes" and "LaneBorders" into two seperate collections
c) Insert each "Lane" between the two required "LaneBorders" using the method "node.insertBefore(newNode,existingNode)" as seen in the code below.
profilesNodeCol = docNode.getElementsByTagName('Profiles'); %Getting all the "Profiles" nodes
for k= 0: profilesNodeCol.getLength-1
profilesK = profilesNodeCol.item(k); %Getting the kth profile
for iCount=0:profilesK.getLength
LBcol = profilesK.item(iCount).getElementsByTagName('LaneBorder'); %Creating a LaneBorder collection
laneCol = profilesK.item(iCount).getElementsByTagName('Lane'); %Creating a Lane collection
for j=0: laneCol.getLength-1
try
profilesK.item(iCount).insertBefore(laneCol.item(j),LBcol.item(j+1)); %Inserting the required Lane between the two required LaneBorders
catch ME
error('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
end
end
end
end
It uses a nesting of 3 for loops. Which is a kind of NO-NO but it acheives the funcionality. If anyone could suggest a better and optimal way, the tip would be really apreciated.
thanks in advance.
Regards, Giri