Read xml file and convert it to aem page

Accepted Solutions (1)

Accepted Solutions (1)




Answers (3)

Answers (3)





Here's how I would do it.

  1. Upload the XML into AEM. The XML should either be a section of your website (including with all it's children)
  2. Create an OSGI service or servlet, Java Backend, to execute the migration logic. (somehow referencing to the XML file)
  3. Implement the migration logic with the Uber Jar AEM libraries such as the PageManager API or the JCR API to clone/create page and edit pages... of course you will need to parse the XML.





There are two options available.


1. Import XML data by scheduler, store it in UGC & use that data on the page based on your requirement.

2. Say storing it in UGC not required, then you can skip saving it in UGC & create page whenever scheduler runs using the xml data.


refer this blog to import & store xml data in UGC.


Thanks for your reply. The article mentioned by you stores xml in jcr, which I have achieved, how can I convert it to html page?

Hi @rk39193348 

Can you add screenshot/code snippet where you are getting service resource resolver null, it will be helpful to find out the issue.

private ResourceResolverFactory resourceResolverFactory;

private static final String SERVICE_USER = "service-user"; //create new service user with required permission
private static final Map<String, Object> SERVICE_USER_DETAILS = ImmutableMap
.of(ResourceResolverFactory.SUBSERVICE, (Object) SERVICE_USER);

public String createPage(String pageName) {"inside createpage****");
try {
ResourceResolver resourceResolver =resourceResolverFactory.getServiceResourceResolver(SERVICE_USER_DETAILS);
//ResourceResolver resourceResolver = slingrequest.getResourceResolver();"resourceResolver****"+resourceResolver.toString());

catch (Exception ex) {"AEMWatchFolderImpl error$$" + ex.getMessage());
return pageName;

using resourceResolver I am trying to create a page, but I am getting null. Can you please help?

pageManager = resourceResolver.adaptTo(PageManager.class);

newPage = pageManager.create(pagePath, pageName, templatePath, pageTitle);


Can you please highlight the line in above code where you are getting null.

I did this - newPage = getPageManager().create(pagePath, "ABC", templatePath, pageTitle); without using resourceResolver it worked.

Now how do I add HTML into it, programmatically?



Assuming as per you comment you are getting null here getPageManager().create(). once we get service resource resolver possibility of getting null return value from this method is less because this method returns page if provide parameters are valid & in some cases throws below error. so please cross check after this method execution whether page is created below this pagePath/rootPath.


Path not found exception : when provide pagePath not exist. (/content/site/root-page)

Access denied : when service user does not have create permission at this pagePath/rootPath. 


newPage = getPageManager().create(pagePath, "ABC", templatePath, pageTitle); 

Now how do I add html dynamically and programmatically to the page?



Hi @rk39193348 ,


First we need to write OSGI service to read data and persist key value properties in CRX repo using JCR API's and once the XML data is available in JCR node properties, we can access and display it on any page.