Page 1 of 1
How to find next node
Posted: Mon Sep 12, 2022 1:27 pm
by shilpa
Hi Team,
I am using Web author, In below xml say my caret position is in first figure node and i would like to know what is the next node is it figure or not how to check that? Need Java api to check the following node of <figure>
Please help on this.
<venue.name>
<figure>
<embedded.figure.reference image-key="RPT.CC.11111111111.00010"
rendition-type="online">Image Online</embedded.figure.reference>
</figure>
<figure>
<embedded.figure.reference image-key="RPT.CC.11111111111.00020"
rendition-type="online">Image Online</embedded.figure.reference>
</figure>
UNITED STATES SUPREME COURT
</venue.name>
Thanks & Regards
Shilpa.P
Re: How to find next node
Posted: Mon Sep 12, 2022 2:09 pm
by cristi_talau
Hello,
I will assume you have an instance of
AuthorNode. In this case you can obtain its siblings using a code like below:
Code: Select all
AuthorNode node = ...;
AuthorParentNode parent = (AuthorParentNode) node.getParent();
List<AuthorNode> siblings = parent.getContentNodes();
Now you can just the element after
node in the list.
Best,
Cristian
Re: How to find next node
Posted: Thu Sep 15, 2022 10:17 am
by shilpa
Hi Cristian,
Actually our requirement is to place the Image Print figure tag below the Image Online figure tag. Below is the example.
<venue.name>
<figure><embedded.figure.reference rendition-type="online">Image Online</embedded.figure.reference></figure>
<figure><embedded.figure.reference rendition-type="print">Image print</embedded.figure.reference></figure>
<figure><embedded.figure.reference rendition-type="online">Image Online</embedded.figure.reference></figure>
<figure><embedded.figure.reference rendition-type="print">Image print</embedded.figure.reference></figure>
</venue.name>
Say now we have 3 Image online tags in the document and i want to insert Print tag below the each of the online tag.
Before inserting i need to verify weather print tag already exist or not.
<venue.name>
<figure><embedded.figure.reference rendition-type="online">Image Online</embedded.figure.reference></figure>
<figure><embedded.figure.reference rendition-type="online">Image Online</embedded.figure.reference></figure>
<figure><embedded.figure.reference rendition-type="online">Image Online</embedded.figure.reference></figure>
</venue.name>
first we are getting all the Online nodes by xpath //figure and then we are iterating the first node say first tag is Online tag, and then here we need to verify what is next node how to do that?
suppose when we write below code to fetch next code then instead of next node(figure) its giving <venue.name> node
AuthorNode nextNode = docCtrl.getNodeAtOffset(node.getEndOffset()+1);
Please suggest on this.
Re: How to find next node
Posted: Thu Sep 15, 2022 1:14 pm
by cristi_talau
Hello,
The code that I included in the first reply can be continued to return the next sibling.
node.getEndOffset() is inclusive, this means that it returns the offset before the end tag of the node. So "node.getEndOffset()+1" returns the offset after the end tag, which is included in the "venue.name" element. For this example, "node.getEndOffset()+2" is in the next figure element.
Best,
Cristian