java - Eclipse RCP 中的 XML 验证

标签 java eclipse-plugin eclipse-rcp

我正在构建一个 Eclipse 插件,我需要在其中“即时”验证 XML 文件。

我创建了一个新的内容类型,以 org.eclipse.core.runtime.xml 作为基本类型,并创建了一个扩展 org.eclipse.wst.sse.ui.StructuredTextEditor 的新编辑器对于此内容类型。 我还为 org.eclipse.wst.validation.validatorV2 做出了贡献,以使用 org.eclipse.wst.xml.core.internal.validation.eclipse.Validator 创建 validator > 验证我的 XML 文件。

这是我的plugin.xml

<plugin>  
   <extension  
         point="org.eclipse.core.contenttype.contentTypes">  
      <content-type  
            base-type="org.eclipse.core.runtime.xml"  
            file-extensions="example"  
            id="com.example.editor.content.example"  
            name="Example Files"  
            priority="normal">  
      </content-type>  
   </extension>  
   <extension  
         point="org.eclipse.ui.editors">  
      <editor  
            class="com.example.editor.ExampleEditor"  
            id="com.example.editor.example"  
            name="Example editor">  
         <contentTypeBinding  
               contentTypeId="com.example.editor.content.example">  
         </contentTypeBinding>  
      </editor>  
   </extension>
   <extension
         id="com.example.validator.ExampleValidator"
         name="Example validator"
         point="org.eclipse.wst.validation.validatorV2">
      <validator
            build="true"
            class="org.eclipse.wst.xml.core.internal.validation.eclipse.Validator"
            manual="true">
         <include>
            <rules>
               <contentType
                     id="com.example.editor.content.example">
               </contentType>
            </rules>
         </include>
      </validator>
   </extension>
</plugin>  

手动验证(右键单击 -> 验证)有效,但文件未“即时”验证(即在用户键入或保存文件时)。

有没有办法在每次保存文件时验证文件以显示可能的错误?

最佳答案

我不久前确实注意到了这个错误。此 org.eclipse.wst.sse.ui.StructuredTextEditor 编辑器无法包含对编辑器的验证。 您是否尝试过扩展内置 XML 编辑器?我想这是可能的,因为在扩展 XML 编辑器的内容类型之后,我不想为我的扩展扩展编辑器。 它会自动验证编辑器。

关于java - Eclipse RCP 中的 XML 验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15572057/

相关文章:

java - Eclipse RCP - SelectionService - 历史?

java - 扩展 Eclipse View 部分的选项卡上下文菜单

Eclipse PDE : How to programmatically detect the auto-build process

java - 如何使用接受用户输入的循环将元素添加到树集中?

java - Holder 中发生某些情况时更新 RecyclerView

java - 如何将参数添加到wiremock中的 stub 响应主体中?

java - 在 OSGI Bundle 中查找文件和文件夹

ant - 如何为 checkstyle 定义抑制定义,同时适用于 ant 和 eclipse

java - JPQL 带条件的左外连接

eclipse-rcp - 如何在 Eclipse RCP 中对菜单中的操作进行排序