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
BedrockMission!

Learn More

View all

Sign in to view all badges

How to read XML file from DAM and place it in JCR?

Avatar

Avatar
Level 1
avinash_gt46739
Level 1

Likes

0 likes

Total Posts

2 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
avinash_gt46739
Level 1

Likes

0 likes

Total Posts

2 posts

Correct Reply

0 solutions
View profile
avinash_gt46739
Level 1

11-07-2018

Hi,

I have a requirement wherein i have to read xml file from dam and place that data under nodes in JCR.

Kindly help on this!

Replies

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,428 likes

Total Posts

3,300 posts

Correct Reply

937 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,428 likes

Total Posts

3,300 posts

Correct Reply

937 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

12-07-2018

Avatar

Avatar
Level 1
avinash_gt46739
Level 1

Likes

0 likes

Total Posts

2 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
avinash_gt46739
Level 1

Likes

0 likes

Total Posts

2 posts

Correct Reply

0 solutions
View profile
avinash_gt46739
Level 1

12-07-2018

Arun,

Thanks,But this doc tells how to read xml file from our local/desktop.But my question is how from aem dam? Any api and how to use it.

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,428 likes

Total Posts

3,300 posts

Correct Reply

937 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,428 likes

Total Posts

3,300 posts

Correct Reply

937 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

12-07-2018

Hi,

You can use Node API to read XML from DAM.

Example:

Node node = req.getResourceResolver().getResource(qs.toString()+"/jcr:content").adaptTo(Node.class);

InputStream in = node.getProperty("jcr:data").getBinary().getStream();

  BufferedReader reader = new BufferedReader(new InputStreamReader(in));

          StringBuilder out = new StringBuilder();

          String line;

          while ((line = reader.readLine()) != null) {

              out.append(line);

          }

          reader.close();

  log.debug("File DATA ==> " + out.toString());

aem63app-repo/ReadFileServlet.java at master · arunpatidar02/aem63app-repo · GitHub

Thanks

Arun

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,409 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,409 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

13-07-2018

Reading an XML will not be any different whether it came from the DAM or a folder on the desktop.

To get the file from the JCR - you can use the JCR API to retrieve the file (Arun Patidar showed a code snippet).

Then use Java logic to read the XML file.