xml-schema xsd错误:带命名空间

时间:2012-07-17 13:11:48

标签: xml namespaces xsd

我正在尝试定义我的第一个xml-schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified"
    targetNamespace="http://www.example.net/test"
    xmlns:t="http://www.example.net/test">

    <xs:annotation>
        <xs:documentation>This schema describes the xml format that is used in for ILTIS stuff.</xs:documentation>
    </xs:annotation>
    <xs:complexType name="station">
        <xs:sequence>
            <xs:element name="transition" type="transition" minOccurs="1" />
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="transition">
        <xs:sequence>
            <xs:element name="wActions" type="wActions" maxOccurs="1" minOccurs="1"/>
            <xs:element name="oActions" type="oAction" maxOccurs="1" minOccurs="1"/>
        </xs:sequence>
        <xs:attribute name="from" type="xs:string" use="required"/>
        <xs:attribute name="to" type="xs:string" use="required"/>
    </xs:complexType>

    <xs:complexType name="wActions">
        <xs:sequence>
            <xs:element name="wMessage" type="wMessage" maxOccurs="2" minOccurs="1"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="oActions">
        <xs:sequence>
            <xs:element name="trainRunMessage" type="trainRunMessage" maxOccurs="2" minOccurs="1"/>
            <xs:element name="wMessage" type="wMessage" maxOccurs="2" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="trainRunMessage">
            <xs:attribute name="track" type="xs:string" use="required"/>
            <xs:attribute name="offset" type="xs:string" default="0"/>
            <xs:attribute name="station" type="xs:string" use="required"/>   
    </xs:complexType>


    <xs:complexType name="wMessage">
        <xs:attribute name="track" type="xs:string" use="required"/>
    </xs:complexType> 
</xs:schema>

但是我的氧气编辑器总是抛出这个错误信息:

src-resolve.4.1: Error resolving component 'transition'. It was detected that 'transition' has no namespace, but components with no target namespace are not referenceable from schema document 'file:/C:/Users/mbohlaender/Desktop/rules-example-schema2.xsd'. If 'transition' is intended to have a namespace, perhaps a prefix needs to be provided. If it is intended that 'transition' has no namespace, then an 'import' without a "namespace" attribute should be added to 'file:/C:/Users/mbohlaender/Desktop/rules-example-schema2.xsd'.

我仍然不知道我做错了什么。 请以简单的方式回答。

1 个答案:

答案 0 :(得分:8)

<transition>元素的定义中,您引用的是transition类型,这是Oxygen无法识别的内容。它不存在。您只在架构中定义了一个名为transition的复杂类型,因此该类型最终位于目标名称空间http://www.example.net/test中,您已使用t前缀导入该名称空间。

尝试写作

<xs:element name="transition" type="t:transition" minOccurs="1" />