Downloading an XML file means triggering a save dialog rather than letting your browser display the code — the trick is using the right click, link attribute, or download button for your specific source.
An XML file holds structured data, and most browsers default to opening it as a collapsible tree view or raw text instead of saving it to your drive. The fix depends on where the file lives — a government database, an email attachment, a web link, or an automated script — and each source has its own best approach. Below are the working methods for every situation.
Why Your Browser Shows the Code Instead of Saving the File
When you click a direct link to an XML file, most browsers (Chrome, Firefox, Edge) treat it as a document to display. The raw text or structured tree loads in the tab, and no download happens. This is the most common point of confusion.
The solution is to either use the browser’s “Save Link As” command (which bypasses the display behavior) or interact with a dedicated download button that sends the right headers. A handful of sources — like the USPTO’s Private PAIR system and REDCap portals — have an explicit XML download button that handles this automatically.
How to Force a Save Dialog on Any Link
Right-click the XML link and choose Save Link As (Chrome, Firefox) or Save target as (Edge). This bypasses the browser’s display handler and opens a save dialog where you can pick the location and confirm the .xml extension.
On a Mac, Control-click the link and select Download Linked File As. On mobile browsers (iOS Safari, Chrome for Android), long-press the link until the context menu appears, then tap Download Linked File or Save to Files.
This single trick works for the vast majority of XML links on the web — no special tools required.
From a Website With a Dedicated Download Button
Some platforms provide an explicit download mechanism that sends the correct HTTP headers, making the file save automatically.
REDCap (NACC documentation). Navigate to the EDC File Downloads page and click the XML link highlighted in the documentation. The file lands in your browser’s download tray. Save it to an accessible folder — you’ll upload it later through REDCap’s “New project” screen using the Choose File button under “Upload a REDCap project XML file (CDISC ODM format).”
USPTO Private PAIR. From the Select New Case screen, choose a radio button under “Search for Application,” enter the related number, and click the orange XML button. When the dialog appears, click Save and pick your storage location. On the Application Search screen alternative, enter the number, click Search, then use the XML button or Download link — then Save.
From an Email Attachment (Outlook.com / Hotmail)
Email providers sometimes convert XML attachments into HTML content when you open them inline. Never click the file name directly — that renders it as a web page inside the email.
Instead, click the Download button or the down arrow next to the attachment name, and choose Download from the menu. After the file saves, verify its extension: if it ends in .html, rename it to .xml manually on your computer. To prevent the conversion entirely, ask the sender to ZIP the XML file before attaching it — email servers handle ZIP attachments without altering the content.
When You Need to Download Multiple XML Files
For researchers, analysts, and developers, one-off downloads get tedious fast. A Python script with the requests library handles bulk XML downloads in seconds.
Install the library once:
pip install requests
Then run a script that fetches each URL and writes the response as a binary file:
import requests
URL = "https://example.com/data/file.xml"
response = requests.get(URL)
with open('feed.xml', 'wb') as file:
file.write(response.content)
The 'wb' mode preserves UTF-8 encoding, so the XML metadata stays intact. Loop through a list of URLs to download hundreds of files automatically.
| Download Method | Best For | Key Caveat |
|---|---|---|
| Save Link As (right-click) | Any direct XML link in a browser | Fails if the link triggers a script, not a direct file URL |
| Dedicated XML button | REDCap, USPTO, government databases | Only works on platforms that provide the button |
| Email Download button | XML attachments in Outlook/Hotmail | File may save as .html; rename manually |
Python requests script |
Bulk or automated downloads | Requires Python installed and requests library |
HTML download attribute |
Website owners linking to XML | Not supported in older Safari versions |
PHP Content-Disposition header |
Server-side forced download | Requires server access and PHP |
| Text editor (copy-paste) | Small XML shown in browser tab | May lose encoding or metadata; last resort |
How Website Owners Can Make XML Always Download
If you run a site that links to XML files and want users to download them instead of viewing them in the browser, two clean methods exist.
The HTML download attribute. Add download to the anchor tag on the link: <a href="file.xml" download>Download XML</a>. You can also specify a custom filename: <a href="file.xml" download="customname.xml">Download</a>. Chrome 47+, Firefox, and Edge support this — older versions of Safari may ignore it and open the file instead.
The PHP header method. On the server side, set the Content-Disposition header to attachment before serving the file: header('Content-Disposition: attachment; filename="file.xml"');. This forces a save dialog regardless of the browser and works universally.
Common Mistakes That Keep the File From Saving Correctly
- Clicking the link instead of right-clicking. A left-click opens the file in the browser tab. Always use Save Link As for direct file URLs.
- Ignoring the file extension after download. An XML attachment saved from Outlook may end in .html. Rename it to .xml before use.
- Copy-pasting content into a text editor. This works in a pinch but can strip encoding declarations, metadata, or special characters that make the XML invalid for its target schema.
- Assuming all browsers handle the
downloadattribute the same. Test on your visitor’s likely browser — if a significant share uses Safari, the PHP header fallback is safer.
USPTO’s documentation on XML file downloads covers the steps for the Private PAIR system. USPTO Quick Start Guide for private PAIR XML downloads provides the full screen-by-screen walkthrough for patent application data.
| Issue | Likely Cause | Fix |
|---|---|---|
| XML displays in tab instead of downloading | Browser treats file as a document | Right-click link → Save Link As |
| File saves as .html | Email server converted attachment | Rename file to .xml, or ask sender to ZIP it |
| Download button does nothing | Link points to a script, not a file URL | Look for a direct file link in page source |
| Python script saves empty or garbled file | URL requires authentication or headers | Add cookies or auth tokens to the request |
| Upload tool rejects the XML | Wrong schema or encoding | Check schema docs (e.g., CDISC ODM for REDCap) |
| Save Link As option is missing on mobile | Mobile browsers minimize context menus | Use a file manager app with a built-in downloader |
| XML has garbled characters when opened | Encoding mismatch during save | Use binary write mode in scripts (wb instead of w) |
Download and Verify in One Sequence
When you need the file saved correctly on the first try, follow this order:
- Identify the source type — web link, email, platform button, or bulk task.
- Use the table above to pick the matching method.
- After the file downloads, check that the extension is .xml — rename if necessary.
- Open the file in a text editor (or browser) and confirm the first line starts with
<?xml version="1.0" encoding="UTF-8"?>or the appropriate schema declaration. - If the file will be uploaded to a system like REDCap, validate it against the target schema before the upload.
That sequence catches the five mistakes people make most often — and it works whether you are grabbing one file or a thousand.
References & Sources
- USPTO. “XML Download Quick Start Guide, v2_09_07_07.” Covers the Private PAIR XML download steps for patent application data.
- NACC Docs. “Introduction to REDCap XML.” Documents the REDCap XML download and upload procedure.
- Pybites. “How to Download an XML File with Python.” Provides the requests library script for automated XML downloads.
- Microsoft Learn. “How to get an XML file as XML, not HTML.” Explains the Outlook.com email attachment conversion issue and the fix.
- Stack Overflow. “How to download an XML without the browser opening it in another tab.” Covers the HTML download attribute and PHP server-side solutions.
