1

我刚刚第一次尝试 XSD。

当我尝试针对我的 XSD 验证我的 XML 时,我收到错误:找不到元素“链接”的声明。

下面我给出了我的 XSD 和我的 XML 的缩减版本。我尝试将命名空间限定符添加到我的 XML 中的顶部元素以及每个元素(将 XSD 更改为限定符),但它没有帮助。我显然犯了一个基本错误。由于我是 XSD 新手,如果您能在我的 XML 和/或 XSD 中包含我需要更改的内容,我将不胜感激。

XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.stephenwaring.me.uk/android/nestedsettings"
    xmlns="http://www.stephenwaring.me.uk/android/nestedsettings"
    elementFormDefault="unqualified">
    <xs:element name="linkage">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="preference-screen" maxOccurs="unbounded">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="parent" maxOccurs="unbounded">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="child" maxOccurs="unbounded">
                                            <xs:complexType>
                                                <xs:attribute name="key" type="xs:token" use="required" />
                                                <xs:attribute name="reformat" type="xs:boolean" />
                                            </xs:complexType>
                                        </xs:element>
                                    </xs:sequence>
                                    <xs:attributeGroup ref="keyed" />
                                    <xs:attribute name="preference-screen" type="xs:token" use="required" />
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                        <xs:attributeGroup ref="keyed"/>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
            <xs:attributeGroup ref="defaults"/>
        </xs:complexType>
    </xs:element>
    <xs:attributeGroup name="defaults">
        <xs:attribute name="html" type="xs:boolean" />
        <xs:attribute name="prefix" type="xs:string" />
        <xs:attribute name="suffix" type="xs:string" />
        <xs:attribute name="separator" type="xs:string"/>
        <xs:attribute name="reformat" type="xs:boolean" />
        <xs:attribute name="shaddow" type="xs:boolean" />   
        <xs:attribute name="child-summary" type="xs:boolean" /> 
        <xs:attribute name="shadow-separator" type="xs:string"/>
    </xs:attributeGroup>
    <xs:attributeGroup name="keyed">
        <xs:attributeGroup ref="defaults" />
        <xs:attribute name="key" type="xs:token" use="required" />
    </xs:attributeGroup>
</xs:schema>

减少 XML:

<?xml version="1.0" encoding="UTF-8"?>
<linkage
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://stevewaring.me.uk/android/nestedsettings nestedsettings.xsd"
    xmlns="http://www.stevewaring.me.uk">
    <preference-screen
        key="preferences1">
        <parent
            key="prefFruit"
            preference-screen="preferences2">
            <child key="prefFruit1"/>
            <child key="prefFruit2"/>
        </parent>
    </preference-screen>
</linkage>
4

1 回答 1

1

您的 XSD 在http://www.stephenwaring.me.uk/android/nestedsettings中定义元素,而您的文档元素在http://www.stevewaring.me.uk中。让他们以一种或另一种方式同意,它应该解决您遇到的错误。

我添加了一个固定的 XML,还有另一个与使用不合格元素有关的问题。

<?xml version="1.0" encoding="UTF-8"?>
<linkage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.stephenwaring.me.uk/android/nestedsettings nestedsettings.xsd" xmlns="http://www.stephenwaring.me.uk/android/nestedsettings">
    <preference-screen xmlns="" key="preferences1">
        <parent key="prefFruit" preference-screen="preferences2">
            <child key="prefFruit1"/>
            <child key="prefFruit2"/>
        </parent>
    </preference-screen>
</linkage>
于 2013-04-15T12:55:39.933 回答