Read xml file and convert it to aem page

Avatar

Avatar
Validate 10
Level 2
rk39193348
Level 2

Like

1 like

Total Posts

92 posts

Correct reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 10
Level 2
rk39193348
Level 2

Like

1 like

Total Posts

92 posts

Correct reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 1
Affirm 1
View profile
rk39193348
Level 2

01-10-2020

Hi all,

 

I have a requirement where I need to read xml file and convert it to aem page. Is there a way to do it?

 

Regards,

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
MVP
Ravi_Pampana
MVP

Likes

197 likes

Total Posts

243 posts

Correct reply

75 solutions
Top badges earned
Establish
Contributor
Shape 1
Ignite 5
Ignite 3
View profile

Avatar
Establish
MVP
Ravi_Pampana
MVP

Likes

197 likes

Total Posts

243 posts

Correct reply

75 solutions
Top badges earned
Establish
Contributor
Shape 1
Ignite 5
Ignite 3
View profile
Ravi_Pampana
MVP

01-10-2020

Answers (3)

Answers (3)

Avatar

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

645 likes

Total Posts

606 posts

Correct reply

239 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

645 likes

Total Posts

606 posts

Correct reply

239 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
BrianKasingli
MVP

01-10-2020

@rk39193348,

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.

 

Avatar

Avatar
Give Back 3
MVP
Manjunath_K
MVP

Likes

140 likes

Total Posts

188 posts

Correct reply

61 solutions
Top badges earned
Give Back 3
Give Back
Boost 50
Boost 5
Boost 3
View profile

Avatar
Give Back 3
MVP
Manjunath_K
MVP

Likes

140 likes

Total Posts

188 posts

Correct reply

61 solutions
Top badges earned
Give Back 3
Give Back
Boost 50
Boost 5
Boost 3
View profile
Manjunath_K
MVP

01-10-2020

@rk39193348 

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.

https://aem.redquark.org/2019/05/import-xml-data-into-aem.html

 

rk39193348
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?
Manjunath_K

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.

rk39193348

 @reference
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) {
log.info("inside createpage****");
try {
ResourceResolver resourceResolver =resourceResolverFactory.getServiceResourceResolver(SERVICE_USER_DETAILS);
//ResourceResolver resourceResolver = slingrequest.getResourceResolver();
log.info("resourceResolver****"+resourceResolver.toString());
}

catch (Exception ex) {
log.info("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);

Manjunath_K

@rk39193348 

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

rk39193348

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

Now how do I add HTML into it, programmatically?

 

Manjunath_K

@rk39193348 

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

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

Avatar

Avatar
Establish
MVP
santhosh_kumark
MVP

Likes

99 likes

Total Posts

111 posts

Correct reply

38 solutions
Top badges earned
Establish
Validate 1
Give Back 3
Give Back
Boost 50
View profile

Avatar
Establish
MVP
santhosh_kumark
MVP

Likes

99 likes

Total Posts

111 posts

Correct reply

38 solutions
Top badges earned
Establish
Validate 1
Give Back 3
Give Back
Boost 50
View profile
santhosh_kumark
MVP

01-10-2020

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.

 

Regards,

Santosh