4

I'd like to use Emacs for XML editing.

A long, long time ago I recall using pSGML to do that.

Now that I've returned to Emacs I'd like to have tag autocompletion and easy navigation in XML files. Unfortunately, pSGML has fallen into disrepair and I have to make do with nXML.

  • This is ...confusing... All this use of outdated external tools... – Deer Hunter Mar 12 '16 at 12:45
  • The more I look at it, the more I see the weak point - adequate transformation of the XSD into a decent RNC. auto-complete-nxml-mode did the trick of autocompletion, although I had to search a bit. Will write up an answer if no one else comes with a tutorial... – Deer Hunter Mar 12 '16 at 21:02
  • Regarding "auto-completion", installing company-mode should be all there is to it. – Stefan Mar 14 '16 at 12:51
1

Turns out the hardest part has to be done outside Emacs.

  • Install auto-complete and auto-complete-nxml from MELPA (easy).
  • Note: don't use genrnc from MELPA 'cause it does not fit the bill...
  • Ensure that xsltproc is installed on the system (easy for Linux/Unix/OSX users).
  • Add the following customization into the user's ~/.emacs file (easy):
 (require 'auto-complete-nxml)
 ;; Keystroke to popup help about something at point.
 (setq auto-complete-nxml-popup-help-key "C-:")
 ;; Keystroke to toggle on/off automatic completion.
 (setq auto-complete-nxml-toggle-automatic-key "C-c C-t")
  • Get the XSD schema for the XML format in use (easy)

  • Convert the XSD file into a RELAX NG Compact format file usable by nXML (hard!)


Approach #1:

  1. get XSDtoRNG converter stylesheet (easy)
  2. run xsltproc XSDtoRNG.xsl MySchema.xsd > MySchema.rng (easy)
  3. get RngToRnc (mostly future-proof)
  4. run xsltproc RngToRncClassic.xsl MySchema.rng > MySchema.rnc (easy)

Approach #2:

  1. find trang and rngconv utilities
  2. ...work in progress...

  • Load the XML file into Emacs. Major mode should be nXML, minor mode should be AC.
  • XML > Set Schema > File ... and choose MySchema.rnc.
  • Manually edit MySchema.rnc when Emacs complains (hard!), save it, and repeat the previous step.
  • Use autocompletion (ESC-TAB) when needed.
| improve this answer | |

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.