0

I have been browsing some examples of avahi services files (XML format), and some of them had <!--*-nxml-*--> comment following the document type definition.

For example:

<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
    <name replace-wildcards="yes">%h</name>
    <service>
        <type>_device-info._tcp</type>
        <port>0</port>
        <txt-record>model=RackMac</txt-record>
    </service>
</service-group>

After searching, I figured this tag purpose was to be interpreted by emacs for its nXML mode. But since I'm not an emacs user myself, this tag seems completely useless as it is.

Is there any convention that says this should be the defaults for XML files (may be only configuration files), or does it has another hidden purpose I can't figure?

2

The XML comment <!--*-nxml-*--> will be ignored by any XML parser, so it has no function whatsoever in terms of the actual meaning or function of the XML from that point of view.

It is only there to allow emacs to do correct highlighting etc.

In vim, this is called a modeline, and would look like

<!-- vim: set filetype=nxml.xml : -->

In Emacs, this is called specifying file local variables, and the slightly longer (compared to what's in your file) format is

<!-- -*- mode: modename; var: value; … -*- -->

This is useful if the editor can't figure out the file's proper type in any other way (from the filename or by using some heuristic matching of the contents). Apart from that, it serves no purpose.

There are no standards, no best practices and no recommendations that say this type of editor-specific comment needs to be added.

  • Hi, thank you for the answer. However, is there any historical reason for adding those Emacs tags or is just a coincidence ? Are there any recommendations about adding these tags or not? – dashdashzako Jan 30 '17 at 6:00
  • @damienc There is absolutely no reason to add those comments to the XML (this is the first time I see it in an XML file), other than providing Emacs with a hint of the file type. There is no standards, no best practices, and no recommendations regarding this. – Kusalananda Jan 30 '17 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.