You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复Notepad++自动补全Schema(XSD)文件

DOORS DXL语言NPP自动补全XML的XSD调试问题

我正在为DOORS DXL语言编写Notepad++(NPP)自动补全XML文件,文件包含约1500个关键词,编辑时的拼写错误很难定位。目前没有对应自动补全XML标签结构的Schema(XSD)文件,所以我首次编写XSD,希望能精准定位错误行。

NPP的XML Tools插件仅能检测结构是否正确,无法发现标签缺失;开启自动验证虽能发现错误,但在大XML文件中定位的区域不准确。我编写的XSD在在线测试时出现报错,提示autocomplete的ref属性错误、序列错误。我尝试用多序列属性强制XML标签排序,但没找到根本问题;删除所有序列后又出现元素报错,继续删除内容也无法修复,没法反向逐步排查。另外,我已经替换了主注释后的元素,确保NotepadPlus标签能被正确处理。


原XSD代码

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           id="NPP-XSD-1"
           elementFormDefault="qualified"
           attributeFormDefault="qualified"
>

    <!-- targetNamespace="C:\Users\tester\Documents\DOORS_RPE_Library\DOORS_DXL_Examples\NotePPlus_DXL_tool" -->
    <!-- xmlns="C:\Users\tester\Documents\DOORS_RPE_Library\DOORS_DXL_Examples\NotePPlus_DXL_tool" -->

<!-- Purpose: XML Schema for Note Pad Plus Autocomple validation. -->

    <!-- Initialization of XML Schema statements for use in the main XML Schema body that follows -->
    <!-- Note: AttributesGroups provides a mechanism to group a set of attribute declarations so that
      they can be incorporated as a group into complex type definitions.
      An attribute group can be defined only as a child of the schema element. 
      In this case, the name attribute must be present and contain the attribute, attributeGroup, 
      or anyAttribute elements that make up the attribute group. 
      When a complexType or an attributeGroup element includes an attribute group, the ref attribute 
      must be present and the name attribute is not allowed.
      
      An attribute group reference can be defined only as a child of the attributeGroup or complexType element.
      In this case, the ref attribute must be present and contain the name of the referenced attribute group.
      
      XML ID value can't be a number,and is a string. Used to uniquely identifier an XML element
      The TargetNamespace is the namespace of all schema components in this schema as well as any schema included 
      using the include element.
      -->

    <!-- Define Group attributes -->

    <xs:attributeGroup name="environmentgroupAttr" id="G_attr-1">
        <xs:attribute name="ignoreCase">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:pattern value="yes|no"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="startFunc" type="xs:string"/>
        <xs:attribute name="stopFunc" type="xs:string"/>
        <xs:attribute name="paramSeparator" type="xs:string"/>
        <xs:attribute name="terminal" type="xs:string"/>
    </xs:attributeGroup>

    <xs:attributeGroup name="keywordgroupAttr" id="G_attr-2">
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="func">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:pattern value="yes|no"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
    </xs:attributeGroup>

    <xs:attributeGroup name="overloadgroupAttr" id="G_attr-3">
        <xs:attribute name="retVal" type="xs:string"/>
        <xs:attribute name="descr" type="xs:string"/>
    </xs:attributeGroup>

    <!-- Define ComplexTypes based on Group Attributes -->

    <xs:complexType name="autocompleteType" mixed="false" id="C_type-1">
        <xs:attribute name="language" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="environmentType" mixed="false" id="C_type-2">
        <xs:attributeGroup ref="environmentgroupAttr"/>
    </xs:complexType>

    <xs:complexType name="keywordType" mixed="false" id="C_type-3">
        <xs:attributeGroup ref="keywordgroupAttr"/>
    </xs:complexType>

    <xs:complexType name="overloadType" mixed="false" id="C_type-4">
        <xs:attributeGroup ref="overloadgroupAttr"/>
    </xs:complexType>

    <xs:complexType name="paramType" mixed="false" id="C_type-5">
        <xs:attribute name="name" type="xs:string"/>
    </xs:complexType>

    <!-- Define Autocomple elements -->

    <xs:element name="AutoComplete" type="autocompleteType"/>
    <xs:element name="Environment" type="environmentType"/>
    <xs:element name="KeyWord" type="keywordType"/>
    <xs:element name="Overload" type="overloadType"/>
    <xs:element name="Param" type="paramType"/>

    <!-- XML Autocomplete Message structure (group) based on earlier defined structures. -->


    <xs:group name="Autocomplete_msg_struct">
        <!-- 1st level -->
        <xs:sequence>
            <xs:element ref="AutoComplete" minOccurs="1" maxOccurs="1">
                <!-- 2nd level -->
                <xs:sequence>
                    <xs:element ref="Environment" minOccurs="1" maxOccurs="1"/>
                    <!-- 3rd level -->
                    <xs:sequence>
                        <xs:element ref="KeyWord" minOccurs="1" maxOccurs="unbounded">
                            <xs:element ref="Overload" minOccurs="1" maxOccurs="unbounded">
                                <xs:element ref="Param" minOccurs="0" maxOccurs="unbounded"/>
                            </xs:element><!-- Overload tag -->
                        </xs:element><!-- KeyWord tag -->
                    </xs:sequence><!-- 3rd level -->
                </xs:sequence><!-- 2nd level -->
            </xs:element><!-- AutoComplete tag -->
        </xs:sequence><!-- 1st level -->
    </xs:group>

    <!-- Main AutoComplete XML message structure for NPP -->

    <xs:element name="NotepadPlus">
        <xs:complexType mixed="false">
            <xs:group ref="Autocomplete_msg_struct"/>
        </xs:complexType>
    </xs:element>
</xs:schema>

修改后的NotepadPlus结构代码

<xs:complexType name="NotepadPlus_struct" mixed="true">
        
            <xs:group ref="Autocomplete_msg_struct" minOccurs="1" maxOccurs="1"/>
        
    </xs:complexType>

    <xs:element name="NotepadPlus" type="NotepadPlus_struct"/>

内容的提问来源于stack exchange,提问作者M SW

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 09:00:59