简体   繁体   English

基于W3C XML Schema的emacs中的模式敏感编辑? (不是RNG)

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

I just learned, here , about nxml-mode , which, according to the README, is a 我刚刚在这里了解到nxml-mode ,根据README,它是一个

major mode for GNU Emacs for editing XML documents. GNU Emacs的主要模式,用于编辑XML文档。 It supports editing well-formed XML documents and also provides schema-sensitive editing of XML documents using RELAX NG Compact Syntax. 它支持编辑格式良好的XML文档,还使用RELAX NG Compact语法提供对XML文档的模式敏感编辑。

Is there a mode that does the same for W3C XML Schema? 有没有一种模式可以为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? 如果我找不到这样的东西,那么无论如何nxml-mode对我有用,假设我严格处理W3C XML Schema而不是Relax-NG?

Related: Schema-aware editing in VIM 相关: VIM中的模式感知编辑

只需使用XSD到RNG转换器,像这样

I tried this with a fairly simplistic XSD schema - one that defined 4 elements of varying type. 我尝试了一个相当简单的XSD架构 - 一个定义了4种不同类型的元素。 Using this schema with nxml-mode required me to run through 3 XSL conversions: 在nxml-mode中使用这个模式需要我运行3次XSL转换:

  • XsdToRNG.xsl - from googlecode as suggested by Alex Ott. XsdToRNG.xsl - 来自Alex Ott建议的googlecode Produces RNG XML Syntax. 生成RNG XML语法。
  • RNGToRncXml.xsl - from Pantor . RNGToRncXml.xsl - 来自Pantor This operates on RNG XML Syntax and produces an "intermediate" representation of the schema which is none of {XSD, RNG, RNC} 这适用于RNG XML语法,并生成模式的“中间”表示,它不是{XSD,RNG,RNC}
  • RNGToRncText.xsl - also from Pantor. RNGToRncText.xsl - 也来自Pantor。 operates on the intermediate format to produce RNC. 以中间格式运行以生成RNC。 (RNG Compact Syntax), which is what nxml-mode wants. (RNG Compact Syntax),这是nxml-mode想要的。

[Prior to this I did not realize that there are two flavors of RNG. [在此之前我没有意识到有两种类型的RNG。 ] ]

The result is a fairly compact RNC file, which is even understandable. 结果是一个相当紧凑的RNC文件,甚至可以理解。

I also tried the same thing with an XSLT XSD, and got similar, positive results: a good .rnc file to use with nxml-mode. 我也尝试使用XSLT XSD做同样的事情,得到了类似的积极结果:一个好的.rnc文件用于nxml-mode。 This turned out to be unnecessary, because nxml-mode ships with a RNC for XSLT. 事实证明这是不必要的,因为nxml-mode附带了一个用于XSLT的RNC。 But it gave me confidence that more complex .XSD files could be converted to .RNC. 但它让我相信更复杂的.XSD文件可以转换为.RNC。

After you get the .RNC, you can use it to guide the editing of an XML document. 获得.RNC后,您可以使用它来指导编辑XML文档。 Open the doc (maybe a new, empty doc), and be sure to run nxml-mode if it isn't automatically done for you. 打开doc(可能是一个新的空文档),如果没有自动为你完成,请确保运行nxml-mode。 Then associate the schema to that document in nxml-mode, using Cc Cs Cf. 然后使用Cc Cs Cf将模式与nxml-mode中的该文档相关联。 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. 将模式与文档关联后,您将获得模式敏感完成(即intellisense)和验证。 nxml-mode shops with .rnc schemas for XSLT, Docbook, and, amusingly, RNG Xml Syntax, and others. nxml-mode商店使用.rnc架构,用于XSLT,Docbook,以及有趣的RNG Xml语法等。

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. 使用Sun RNG Converter将XSD转换为RNG / XML,然后使用Trang将RNG转换为RNG紧凑语法。 You can download the Sun converter from msv.java.net. 您可以从msv.java.net下载Sun转换器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM