Search code examples
angularxmlangular7

Angular open new window and display xml


I would like to open a new window after a click event and show an xml structure. I do not want that browser interpret my xml.

I tried with this:

window.open('data:text/xml;charset=utf-8,<?xml version="1.0" encoding="UTF-8"?><RootTag>'+xml+'</RootTag>', "", "_blank")

with chrome this do not work.


Solution

  • I solved this problem with this code in the component.ts

        let blob = new Blob([text], {type: 'text/xml'});
        let url = URL.createObjectURL(blob);
        window.open(url);
        URL.revokeObjectURL(url);
    

    This open a new window with the view just for xml.