Out of the box, AEM can render content in XML and HTML, as well as JSON and others. See this similar question.
You'll want to read the Sling Cheatsheet and the Sling docs regarding Apache Sling script resolution. Read about Sling rendering with the default Get servlet.
The same content in the JCR can be rendered in different formats by changing the URL extension. So if you have a cq:Page
resource at /content/projectname/page
, you can retrieve XML by making a simple GET request to /content/projectname/page.xml
. Likewise you can retrieve HTML at /content/projectname/page.html
and JSON at /content/projectname/page.json
.
As for your question on how AEM renders handles the rendering internally, it's actually the responsibility of Apache Sling. You can examine the open source code on GitHub including the different renderers.