Hello guys,
I have the following node structure it can vary depending on how the author created the page. I want to query the content of each headline, textfield, image or link field.
It should just be the last node in every branch the type and depth is not important and fixed.
How can I achieve this starting from the root node "press-releases"?
This only delivers the next node for example "par", but I don't want to iterate through all until I have the last child node of a branch.
NodeIterator subnodes = node.getNodes();
Solved! Go to Solution.
I understand you can use query to get node or results as aspected but it costs more burden on server. so if content is less pls go head and use query if not pls use node iteration logic
sample sudo code
NodeIterator subnodes = result.getNodes();
StringBuilder output = new StringBuilder();
while (nodes.hasNext()) {
Node node = nodes.nextNode();
if(node!= null){
String nodeName= node.getName();
if(nodeName.contains("headline")||nodeName.contains("textfield")||nodeName.contains("image") ||nodeName.contains("link")) {
//busniess logic
}
}
}
I believe you need to write a query which should have following things:
- path : root from where you want your search
- ORing of all expected resource types(I believe this one is better than using node name like highlight/image,etc)
This will give you list of all such nodes and you can perform whatever operation there on
Can you give me some example code please?
Thanks so far.
Views
Replies
Total Likes
There are lots of examples on the internet of using JCR SQL2 to iterate through nodes and retrieve values. For example:
I understand you can use query to get node or results as aspected but it costs more burden on server. so if content is less pls go head and use query if not pls use node iteration logic
sample sudo code
NodeIterator subnodes = result.getNodes();
StringBuilder output = new StringBuilder();
while (nodes.hasNext()) {
Node node = nodes.nextNode();
if(node!= null){
String nodeName= node.getName();
if(nodeName.contains("headline")||nodeName.contains("textfield")||nodeName.contains("image") ||nodeName.contains("link")) {
//busniess logic
}
}
}
Hi Tim
Is there any specific use-case that you want to query this page level (your headline component, text component, link component should render their properties component level right ?)? Could you please help me understand the exact requirement ?
Views
Replies
Total Likes
Hi Veena,
I want to export the content in some structure and feed it to an android app maybe. So I want to extract all headlines, images und text field and put them in a new html structure and the app just call it and display it.
Views
Replies
Total Likes
But does it iterate to every sub node? I think it iterates only the next child nodes of the given node.
Views
Replies
Total Likes
yes for now this sudo code iterates only child nodes. To iterate every sub node we have to update logic.
Views
Replies
Total Likes
Can you explain how to?
Views
Replies
Total Likes
Views
Likes
Replies