Schema-sensitive editing in emacs, based on W3C XML Schema? (not RNG)

你。 提交于 2019-12-03 03:08:47

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!