什么是错误“元素不能包含空格。内容模型是空的。“是什么意思?

时间:2021-12-23 16:55:32

I'm putting together an xml schema for a simple xml (see bellow for both xml and schema). But I keep getting the following error with regards to the section node: "The element cannot contain white space. Content model is empty." . Browsing the net I could not find any concise explanation as to what it means so I can fix it. Can anyone help?

我正在为一个简单的xml整理一个xml架构(请参阅下面的xml和schema)。但是对于节节点,我不断收到以下错误:“元素不能包含空格。内容模型为空。” 。浏览网络我找不到任何简洁的解释,这意味着我可以解决它。有人可以帮忙吗?

Edit: thanks for all for offering help with the schema. I think it would help to have a concise description of what content model is and why it is empty here.

编辑:感谢所有人提供有关架构的帮助。我认为这将有助于简要描述内容模型是什么以及为什么它在这里是空的。

XML:

XML:

<config>
   <section name="facets">
      <facet type="format" label="Format" max="4"/>
      <facet type="language" max="4"/>
      <facet type="pubdate" max="6" submax="8"/> 
      <facet type="ice_topic" label="Fiction: Topic"/>
   </section>
</config>

Schema:

架构:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <xs:element name="config">
      <xs:complexType>
         <xs:sequence>
            <xs:element name="section" type="sectionBase"/>
         </xs:sequence>
      </xs:complexType>
   </xs:element>
   <xs:complexType name="sectionBase">
      <xs:attribute name="name" type="xs:ID"/>
   </xs:complexType>


   <xs:complexType name="sectionFacets" >
      <xs:complexContent>
         <xs:extension base="sectionBase">
            <xs:sequence>
               <xs:element name="facet" type="sectionFacetsBaseFacet"/>
            </xs:sequence>
         </xs:extension>
      </xs:complexContent>
   </xs:complexType>
   <xs:complexType name="sectionFacetsBaseFacet">
      <xs:attribute name="label" type="xs:ID"/>
      <xs:attribute name="max" type="xs:positiveInteger"/>
   </xs:complexType>
   <xs:complexType name="sectionFacetsFormat">
      <xs:complexContent>
         <xs:extension base="sectionFacetsBaseFacet"/>
      </xs:complexContent>
   </xs:complexType>
   <xs:complexType name="sectionFacetsPubdate">
      <xs:complexContent>
         <xs:extension base="sectionFacetsBaseFacet">
            <xs:attribute name="submax" type="xs:positiveInteger"/>
         </xs:extension>
      </xs:complexContent>

   </xs:complexType>
</xs:schema>

3 个解决方案

#1


2  

The label attribute of facet is set to xs:ID and this doesn't allow spaces. You might want to use xs:string instead.

facet的label属性设置为xs:ID,这不允许使用空格。您可能希望使用xs:string。

#2


1  

There are several problem in our schema as others have already mentioned. Try something like this:

我们的架构中存在一些问题,正如其他人已经提到的那样。尝试这样的事情:

The extensible schema:

可扩展的架构:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <!-- never used; just to be extended -->
    <xs:complexType name="sectionBaseType" abstract="true">
        <xs:attribute name="name" type="xs:ID"/>
    </xs:complexType>

    <!-- extension of the sectionBaseType -->
    <xs:complexType name="sectionSpecialized">
        <xs:complexContent>
            <xs:extension base="sectionBaseType">
                <xs:sequence>
                    <xs:element name="facet" type="leftToTheReaderType"
                        maxOccurs="unbounded"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <!-- config may contain a single section or one of its extensions -->
    <xs:complexType name="configType">
        <xs:sequence>
            <xs:element name="section" type="sectionBaseType"/>
        </xs:sequence>
    </xs:complexType>

    <!-- a single root node called "config" -->
    <xs:element name="config" type="configType"/>
</xs:schema>

How to use the schema:

如何使用架构:

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <!-- note the xsi:type to specify the actual type of the section!! -->
    <section name="facets"
        xsi:type="sectionSpecialized">
        <facet .../>
        <facet .../>
        <facet .../> 
        <facet .../>
    </section>
</config>

#3


0  

Your section element is defined as type sectionBase, and the sectionBase type definition only defines a single attribute. There's no reference anywhere in the schema to the sectionFacets type, which is probably what you need.

您的section元素定义为typeBase类型,sectionBase类型定义仅定义单个属性。模式中的sectionFacets类型中没有任何引用,这可能就是您所需要的。

Try changing the type of the section element to sectionFacets

尝试将section元素的类型更改为sectionFacets

#1


2  

The label attribute of facet is set to xs:ID and this doesn't allow spaces. You might want to use xs:string instead.

facet的label属性设置为xs:ID,这不允许使用空格。您可能希望使用xs:string。

#2


1  

There are several problem in our schema as others have already mentioned. Try something like this:

我们的架构中存在一些问题,正如其他人已经提到的那样。尝试这样的事情:

The extensible schema:

可扩展的架构:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <!-- never used; just to be extended -->
    <xs:complexType name="sectionBaseType" abstract="true">
        <xs:attribute name="name" type="xs:ID"/>
    </xs:complexType>

    <!-- extension of the sectionBaseType -->
    <xs:complexType name="sectionSpecialized">
        <xs:complexContent>
            <xs:extension base="sectionBaseType">
                <xs:sequence>
                    <xs:element name="facet" type="leftToTheReaderType"
                        maxOccurs="unbounded"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <!-- config may contain a single section or one of its extensions -->
    <xs:complexType name="configType">
        <xs:sequence>
            <xs:element name="section" type="sectionBaseType"/>
        </xs:sequence>
    </xs:complexType>

    <!-- a single root node called "config" -->
    <xs:element name="config" type="configType"/>
</xs:schema>

How to use the schema:

如何使用架构:

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <!-- note the xsi:type to specify the actual type of the section!! -->
    <section name="facets"
        xsi:type="sectionSpecialized">
        <facet .../>
        <facet .../>
        <facet .../> 
        <facet .../>
    </section>
</config>

#3


0  

Your section element is defined as type sectionBase, and the sectionBase type definition only defines a single attribute. There's no reference anywhere in the schema to the sectionFacets type, which is probably what you need.

您的section元素定义为typeBase类型,sectionBase类型定义仅定义单个属性。模式中的sectionFacets类型中没有任何引用,这可能就是您所需要的。

Try changing the type of the section element to sectionFacets

尝试将section元素的类型更改为sectionFacets