views:

575

answers:

3

I just learned, here, about nxml-mode, which, according to the README, is a

major mode for GNU Emacs for editing XML documents. It supports editing well-formed XML documents and also provides schema-sensitive editing of XML documents using RELAX NG Compact Syntax.

Is there a mode that does the same for W3C XML Schema?

If I cannot find such a thing, then is nxml-mode useful to me anyway, assuming I deal strictly with W3C XML Schema and not with Relax-NG?

Related: Schema-aware editing in VIM

+5  A: 

Just use XSD to RNG converter, like this

Alex Ott
I don't think this works, because it produces Relax-NG, not Relax-NG Compact Syntax. Maybe there is another conversion I have to run through.
Cheeso
I think this might work for the 2nd conversion: http://www.pantor.com/download.html It is a RNG-to-RNC conversion sheet. Actually, the RNG-to-RNC is also a 2 stage conversion. !! Getting pretty fractal.
Cheeso
Ok, this actually worked well!
Cheeso
+1  A: 

Even without schemas it is quite useful. You can auto-complete closing tags, navigate by tag and lots of other great bells and whistles. All that said, Alex Ott is right on the money.

Jonathan Arkell
+4  A: 

I tried this with a fairly simplistic XSD schema - one that defined 4 elements of varying type. Using this schema with nxml-mode required me to run through 3 XSL conversions:

  • XsdToRNG.xsl - from googlecode as suggested by Alex Ott. Produces RNG XML Syntax.
  • RNGToRncXml.xsl - from Pantor. This operates on RNG XML Syntax and produces an "intermediate" representation of the schema which is none of {XSD, RNG, RNC}
  • RNGToRncText.xsl - also from Pantor. operates on the intermediate format to produce RNC. (RNG Compact Syntax), which is what nxml-mode wants.

[Prior to this I did not realize that there are two flavors of RNG. ]

The result is a fairly compact RNC file, which is even understandable.

I also tried the same thing with an XSLT XSD, and got similar, positive results: a good .rnc file to use with nxml-mode. This turned out to be unnecessary, because nxml-mode ships with a RNC for XSLT. But it gave me confidence that more complex .XSD files could be converted to .RNC.

After you get the .RNC, you can use it to guide the editing of an XML document. Open the doc (maybe a new, empty doc), and be sure to run nxml-mode if it isn't automatically done for you. Then associate the schema to that document in nxml-mode, using C-c C-s C-f. This is necessary only the first time editing a doc - thereafter the schema can be associated to the doc automagically.

Once a schema is associated to a doc, you get schema-sensitive completion (aka intellisense) and validation. nxml-mode shops with .rnc schemas for XSLT, Docbook, and, amusingly, RNG Xml Syntax, and others.

It takes a little setting up, but it works.

Cheeso