How can a user open a new window and display XML content in a clear format when clicking a link on an existing HTML page?

To open a new window and display XML content in a clear format when clicking a link on an existing HTML page, you can use JavaScript to open a new window and load the XML content using an XMLHttpRequest. You can then format the XML content using HTML and display it in the new window.

<!DOCTYPE html>
<html>
<head>
    <title>Display XML Content</title>
    <script>
        function displayXMLContent() {
            var xmlRequest = new XMLHttpRequest();
            xmlRequest.open("GET", "example.xml", false);
            xmlRequest.send(null);
            var xmlContent = xmlRequest.responseText;
            
            var newWindow = window.open("", "_blank");
            newWindow.document.write("<pre>" + xmlContent + "</pre>");
        }
    </script>
</head>
<body>
    <a href="javascript:void(0);" onclick="displayXMLContent();">Click here to display XML content</a>
</body>
</html>