find all node value after the current node for a specific node

Having trouble installing Oxygen? Got a bug to report? Post it all here.
SmitaraniB
Posts: 3
Joined: Tue Nov 29, 2022 1:44 pm

find all node value after the current node for a specific node

Post by SmitaraniB »

Hi Team,

I wanted to check if we can get all the node value after the selected node in the sequence they are present to a variable.
Capture_pdc.PNG
Capture_pdc.PNG (97.13 KiB) Viewed 376 times
in the attachment I am at the selected pdc.number element tag with value 34 and I want all the values in the pdc element tag value sequentially using js file.


Thanks,
Smita
cristi_talau
Posts: 496
Joined: Thu Sep 04, 2014 4:22 pm

Re: find all node value after the current node for a specific node

Post by cristi_talau »

Hello,

I would try to make a DFS traversal of the DOM tree and start collecting values of the "pdc" element tag after we encounter the currently selected node.
The steps will imply:
  • Obtaining the "#document" element of the XML DOM tree
  • Obtaining the currently selected node
  • Iterating the tree and collecting the desired nodes
If you want to go into more details regarding one of the steps, please let me know.

Another approach is to obtain the "#document" node, and the "getElementsByTagName()" method to obtain your "pdc.number" elements. You can also use Node.compareDocumentPosition(otherNode) to filter the ones that come after the selection.

Best,
Cristian
Post Reply