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

后端 未结 4 903
轻奢々
轻奢々 2021-02-06 05:00

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 we

相关标签:
4条回答
  • 2021-02-06 05:28

    Just use XSD to RNG converter, like this

    0 讨论(0)
  • 2021-02-06 05:29

    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.

    0 讨论(0)
  • 2021-02-06 05:32

    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.

    0 讨论(0)
  • 2021-02-06 05:49

    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.

    0 讨论(0)
提交回复
热议问题