Highlighted

How to remove childNode in AEM

Avatar

Avatar

drumilk92707948

Avatar

drumilk92707948

drumilk92707948

06-08-2019

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

Replies

Highlighted

Avatar

Avatar

anujg3325839

Avatar

anujg3325839

anujg3325839

06-08-2019

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 );
 
}

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

Highlighted

Avatar

Avatar

drumilk92707948

Avatar

drumilk92707948

drumilk92707948

06-08-2019

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

/content

     /person

          /name

          /age

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

Highlighted

Avatar

Avatar

jbrar

Employee

Avatar

jbrar

Employee

jbrar
Employee

06-08-2019

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