2013-03-22 69 views
1

我正在构建一个eclipse插件,我需要在“实时”验证XML文件。Eclipse RCP中的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验证我的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> 

手动验证(右键 - >验证)的作品,但该文件没有“对飞”(即验证当用户键入或文件的时候保存)。

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

回答

0

我前一阵子注意到了这个错误。这个org.eclipse.wst.sse.ui.StructuredTextEditor编辑器无法包含对编辑器的验证。 您是否尝试过扩展内置的XML编辑器?我想在扩展XML编辑器的内容类型之后,我可能会考虑这么做,因为我并没有为扩展名扩展编辑器。 它自动验证编辑器。

+1

感谢您的回答。我决定尝试扩展一个新的XML编辑器。我选择扩展Rinzo XML Editor(http://editorxml.sourceforge.net/)并完成这项工作。 – user2198936 2013-07-17 12:26:47