I have XML stream code which is generating the xml like shown below. Code and generated xml is shown below. Now, I want to read another XML file from AEM DAM (content shown below) and append to the xml generated using XMLStreamWriter stream.
XML Stream code is shown below
XMLOutputFactory of = XMLOutputFactory.newFactory();
XMLStreamWriter writer of.createXMLStreamWriter(slingResponse.getWriter());
stream.writeStartDocument("1.0");
stream.writeStartElement("", “list", “http://www.google.com/schemas/list/1.1");
stream.writeNamespace("", “http://www.google.com/schemas/list/1.1”);
writer.writeStartElement(NS, “books”);
writer.writeStartElement(“http://www.google.com/schemas/list/1.1”, “name”)
writer.writeCharacters(“test1”);
writer.writeEndElement();
writer.writeStartElement(“http://www.google.com/schemas/list/1.1”, “author”)
writer.writeCharacters(“sample1”);
writer.writeEndElement();
writer.writeEndDocument();
Above code is generating the xml file like this -
<list xmlns="http://www.google.com/schemas/list/1.1">
<books>
<name>test1</loc>
<author>sample1</author>
</books>
<books>
<name>test2</loc>
<author>Sample2</author>
</books>
<books>
<name>test3</loc>
<author> Sample3</author>
</books>
</list>
Now, below is the content of XML which is stored in AEM DAM. Here, I want to read this XML file from AEM DAM and append to the xml generated(above) using XMLStreamWriter stream
<list xmlns="http://www.google.com/schemas/list/1.1">
<books>
<name>test4</loc>
<author>sample4</author>
</books>
<books>
<name>test5</loc>
<author>Sample5</author>
</books>
<books>
<name>test6</loc>
<author> Sample6</author>
</books>
</list>
Currently, I have below code snippet to access the file from AEM DAM. But how to read this xml file and write to XMl stream?
Map<String, String> map = new HashMap<String, String>();
map.put("type", "dam:Asset");
map.put("path", "/content/dam/sample/en");
map.put ("property", "jcr:content/metadata/dc:format");
map.put ("property.value", "application/xml");
builder= resourceResolver.adaptTo(QueryBuilder.class);
Query query = builder.createQuery(PredicateGroup.create(map), session);
SearchResult sr= query.getResult();
Finally, i want output like this -
<list xmlns="http://www.google.com/schemas/list/1.1">
<books>
<name>test1</loc>
<author>sample1</author>
</books>
<books>
<name>test2</loc>
<author>Sample2</author>
</books>
<books>
<name>test3</loc>
<author> Sample3</author>
</books>
<books>
<name>test4</loc>
<author>sample4</author>
</books>
<books>
<name>test5</loc>
<author>Sample5</author>
</books>
<books>
<name>test6</loc>
<author> Sample6</author>
</books>
</list>