Apply styling and formating to XML in MS Word?

I have some text, that is actually an XML snippet, which I want to display in an MS Word document. I really don't want to laboriously style every element and attribute by hand - is there some auto-style I can apply? Is there another solution?

asked Sep 6, 2010 at 11:39 573 4 4 gold badges 7 7 silver badges 11 11 bronze badges

4 Answers 4

You can use Notepad++. After installing:

answered Apr 30, 2013 at 19:24 451 4 4 silver badges 2 2 bronze badges Unfortunately the colours don't come across Commented Feb 14, 2020 at 3:46

I've tended to use Copy HTML to Clipboard. But I've just discovered that the RTF option doesn't have all the annoyances of the HTML option. However, one annoyance remains: it insists on setting the style to Normal for the pasted text, regardless of the style already being used where I'm pasting it or anything else. If I reapply the style I want after pasting, I tend to lose one or two of the colours.

Commented Dec 22, 2022 at 15:54

Use an external highlighter such as pygmentize to generate HTML, then copy and paste that into the document.

answered Sep 6, 2010 at 11:48 Ignacio Vazquez-Abrams Ignacio Vazquez-Abrams 113k 11 11 gold badges 207 207 silver badges 250 250 bronze badges

Create a new style that formats the XML the way you want. The style will likely need to include:

To use this, select the XML text and change the style. All the formatting attributes will be applied at once.

The upside is that XML is text in the document. You can edit it like any other text if you need to make corrections; search for it, etc. The downside of this method is that syntax colouring won't be applied to the text unless it was already there when the text was pasted.

Save the style in the normal.dot template (the default) so that it's available in all documents.

If you need to do this often, you can assign a keyboard shortcut to the text so you don't have to select the style from the style menu.