How to Print an XML File on Windows, Mac and Phone
In this article
- Printing an XML file in six steps
- How to tell the printout worked
- The one problem almost everyone hits: a wall of text
- Worked example: printing a 40 KB order file
- Before you start: a quick checklist
- Which program should you print XML from?
- Printing XML without wasting paper
- Why does my XML open as an error page?
- Does printing change the XML file itself?
Open the XML file in a text editor or web browser and use File > Print, just like printing any document. If the XML is one long unbroken line, pretty-print it first (indent the tags) so the printed copy is readable.
Time 5 min · Steps 6 · Level Easy
Printing an XML file in six steps
- Open the file. Double-click the .xml file. Windows typically opens it in a web browser (Edge or Chrome); macOS often opens it in TextEdit or Safari. If nothing happens, right-click the file and choose Open with, then pick Notepad on Windows or TextEdit on Mac.
- Check the layout. Look at the text. If every tag sits on its own indented line, skip to step 4. If you see one extremely long line with a horizontal scrollbar, you need to pretty-print first (step 3).
- Pretty-print a single-line file. In a browser, press Ctrl+U (Windows) or Cmd+Option+U (Mac) to view the source, which usually shows the indented version. Alternatively, paste the file into a free online XML formatter, choose an indent of 2 or 4 spaces, format it, and save or copy the result. Menu names and shortcuts can differ slightly by version.
- Open the print dialog. Choose File > Print, or press Ctrl+P (Windows) or Cmd+P (Mac). In a browser you can also click the three-dot menu and choose Print.
- Set the paper options. Pick portrait for most XML, or landscape if your lines are long. Set the scale to "Fit to page width" or around 70-80% so long tag lines do not get cut off at the right edge.
- Print or save as PDF. Choose your printer and click Print. To share the file instead of paper, choose "Save as PDF" or "Microsoft Print to PDF" (Windows) / "Save as PDF" (Mac) as the printer destination.
How to tell the printout worked
Check three things on the printed page: the opening <?xml version="1.0"?> declaration appears at the top, every closing tag such as </order> is visible rather than truncated, and no line runs off the right margin. If a line is cut mid-tag, reprint at a smaller scale (try 65-70%) or switch to landscape.
The one problem almost everyone hits: a wall of text
Most XML files are saved without line breaks, so printing them raw produces a few pages of solid text that is nearly useless to read. The fix is pretty-printing before printing. The quickest route: paste the XML into an online formatter, set the indent to 2 spaces, format, then print the result from your browser. In Visual Studio Code, open the file, right-click and choose "Format Document" (you may need to install an XML extension first), then print. In Notepad++ on Windows, choose Plugins > Plugins Admin, install "XML Tools", then use XML Tools > Pretty print. Labels can differ slightly between versions.
Worked example: printing a 40 KB order file
Say you have an orders.xml file of about 40 KB (roughly 40,000 characters) that arrives as a single line. Pasting it into a formatter with 2-space indents typically expands it to about 90-120 printed lines per 10 KB, so expect roughly 400-500 lines total. At the default 10-12 point font that is about 8-10 pages on A4 or Letter paper. Setting the scale to 75% usually brings that down to about 6-7 pages while keeping the text readable. If you only need one section, such as a single <order> block, copy just that block into a new file and print that instead, one page instead of ten.
Before you start: a quick checklist
- The file ends in .xml and opens as text, not as an error page.
- You know whether you need the whole file or just one section, printing a section saves most of the paper.
- Long lines are indented or wrapped, so nothing is cut off at the margin.
- If you want a PDF instead of paper, your print dialog offers a "Save as PDF" destination.
- The file contains no passwords or private data if you are printing to a shared printer.
Which program should you print XML from?
A browser is the fastest for a quick, one-off print, and its source view is usually already indented. Notepad (Windows) prints but does not format XML, so use it only for files that are already indented. TextEdit on Mac works the same way. Visual Studio Code and Notepad++ are the better choice when you print XML often, because they can format, wrap long lines, and show line numbers, which helps when you discuss the printout with someone else. On a phone, open the XML in a browser, request the desktop site if needed, and use the browser's share or print menu to send it to a printer or save it as PDF, though formatting on a phone is more fiddly.
Printing XML without wasting paper
XML files with thousands of lines can run to dozens of pages. Three habits keep the printout manageable: print only the section you need, use the browser's print preview (under File > Print, before you commit) to count pages, and prefer "Save as PDF" when the goal is sharing rather than reading on paper. A PDF also lets you search the text later, which paper does not.
Why does my XML open as an error page?
If your browser shows an error instead of the file's contents, the XML has a syntax problem, often a missing closing tag or a stray character, and the browser refuses to display it. The error message usually names the line number. Open the file in a text editor, go to that line, fix the tag, save, and try printing again. If the file is simply very large, the browser may render it slowly or partially, in that case print from a text editor or formatter instead.
Does printing change the XML file itself?
No. Printing only reads the file. Pretty-printing, however, rewrites the file's whitespace when you save it, which is harmless to any program that reads the XML but does change the file on disk. If you need the original untouched, format a copy: duplicate the file, format the copy, print the copy, delete it afterwards.
Official source: W3C