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
Just use XSD to RNG converter, like this
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.
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.
Use the Sun RNG Converter to get the XSD into RNG/XML, and then Trang to get the RNG into RNG compact syntax. You can download the Sun converter from msv.java.net.
来源:https://stackoverflow.com/questions/917337/schema-sensitive-editing-in-emacs-based-on-w3c-xml-schema-not-rng