Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

How to remove childNode in AEM

Avatar

Level 1

I would like to remove the child node by keeping the parent node hierarchy as is. can someone help how to achieve this.

For e.g.

/content

     /person

          /name

          /age

I would like to remove only child node "/name" here

0 Replies

Avatar

Level 3

you can use various ways via code using java JCR  API

----

Node root = getJcrSession().getRootNode();
 
String path = getFacetPath( repositoryId, facetId, name );
 
if ( root.hasNode( path ) )
 
{
 
Node node = root.getNode( path );
 
do
 
{
 
// also remove empty container nodes
 
Node parent = node.getParent();
  node
.remove();
  node
= parent;
 
}
 
while ( !node.hasNodes() );
 
}
 
}
 
catch ( RepositoryException e )
 
{
 
throw new MetadataRepositoryException( e.getMessage(), e );
 
}

---------------

Avatar

Level 1

I would like to retain the parent structure for e.g.

/content

     /person

          /name

          /age

/content/person should retain while "name" is removed only

Avatar

Employee Advisor

Another way would be to run the groovy script to remove a node from a specific path. check [1] and "Remove corrupted nodes manually" at [2] on how to use it.

This should only remove the child node

[1] Groovy script to remove a node at a given path · GitHub

[2] Offline Compaction fails with SegmentNotFoundException & IllegalArgumentException