Automatically set language to XML when file starts with an XML header

  • bouvierr

    bouvierr - 2014-02-08

    Currently, Notepad++ recognizes XML files by their file name extension (.xml). Opening a ".xml" file enables XML syntax highlighting and collapsible nodes.

    But there are many kinds of files with various extensions other ".xml" that contain XML (.config, .csproj, .csproj.user, .manifest, ...). It is impractical to list all extensions for XML content files in the Notepad++ configuration file.

    I propose a simple workaround. When opening a file, if the extension is not already recognized by Notepad++, read the beginning of the file and look for an XML declaration (<?xml version="1.0" encoding="utf-8"?>). If the declaration is found, then set the language to XML.

    Of course, there are some minor details to think about like what if the declaration is preceded by whitespace. Also, this feature should probably be avoided for very large files (10+ MB), since the analysis of the XML content can take some time.

    All in all, I think this is a pretty simple addition that many users could find useful. What do you think?

    Last edit: bouvierr 2014-02-08
  • cchris

    cchris - 2014-02-16

    If indeed there are too many extensions whichshould be aliased with .xml, so that the usual mehanism becomes unpractical, then it is probably a good thing to consider. Please post a feature request ticket about it.