Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular4: How do I generate an XML file and return it to the browser

Forgive me, for I am relatively new to Angular 4, but I am stuck on something...

I would like when a user goes to https://example.com/sitemap in their web browser...

  1. Data is queried from Firebase
  2. An XML structure is built from this data
  3. (THIS IS THE ONE I CAN NOT FIGURE OUT) XML is returned to the user's web browser with a content type of application/xml (i.e. the <head>, <body>, <script> and other contents of my src/index.html, should not be included in the response).

I have done plenty of Googling and searching Stack Overflow -- but everything I find is just about ingesting an XML document, or writing XML to a page, but not writing an XML document back to the web browser.

Working examples would be appreciated, as I am still learning all the in's and out's of Angular 4.

like image 728
eat-sleep-code Avatar asked May 05 '17 14:05

eat-sleep-code


People also ask

How do I display XML code in browser?

View an XML file in a browser In Chrome, just open a new tab and drag the XML file over. Alternatively, right click on the XML file and hover over "Open with" then click "Chrome".

How do I display XML in angular 8?

After creating the project, open the project in your favorite editor and install the "timers" npm package. This package is necessary for reading an XML file with xml2js package. Open the index. html present at root folder and add a reference for Bootstrap and jQuery.

How do I save as XML?

Click File > Save As, and select the location where you want to save the file. , point to the arrow next to Save As, and then click Other Formats. In the File name box, type a name for the XML data file. In the Save as type list, click XML Data, and click Save.


1 Answers

As nobody could seem to offer an answer, I created my rather own hacky answer. As I am using Firebase for hosting, I leveraged Firebase Storage API to save off my sitemap.xml file and then forward the browser to the just generated document.

like image 110
eat-sleep-code Avatar answered Oct 16 '22 06:10

eat-sleep-code