MaxOccurs,无效内容和更多模式

时间:2015-03-25 21:15:43

标签: xml schema

好的初始查询是固定的,但我还是有些困惑,我很困惑。

这里是xml:

<?xml version="1.0" encoding="UTF-8"?>
<bookstore xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='schema.xsd'>
    <book category="COOKING">
      <title lang="en">Everyday Italian</title>
      <author>Giada De Laurentiis</author>
      <year>2005</year>
      <price>30.00</price>
      <photo>http://puu.sh/gNzTB/258d022e33.jpg</photo>
    </book>

    <book category="CHILDREN">
      <title lang="en">Harry Potter</title>
      <author>J K. Rowling</author>
      <year>2005</year>
      <price>29.99</price>
      <photo>http://puu.sh/gNzV9/e27dfc1b55.jpg</photo>
    </book>

    <book category="WEB">
      <title lang="en">XQuery Kick Start</title>
      <author>James McGovern</author>
      <author>Per Bothner</author>
      <author>Kurt Cagle</author>
      <author>James Linn</author>
      <author>Vaidyanathan Nagarajan</author>
      <year>2003</year>
      <price>49.99</price>
    </book>

    <book category="WEB">
      <title lang="en">Learning XML</title>
      <author>Erik T. Ray</author>
      <year>2003</year>
      <price>39.95</price>
    </book>
</bookstore>

继承架构:

<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<!-- define elements (elements with attributes or other elemens inside are complex) -->
    <xsd:element name='author' type='xsd:string' />
    <xsd:element name='year' type='xsd:gYear' />
    <xsd:element name='price' type='xsd:decimal' />
    <xsd:element name='photo' type='xsd:anyURI' />

<!-- define attributes -->
    <xsd:attribute name='category' type='xsd:string'/>
    <xsd:attribute name='lang' type='xsd:string'/>

<!-- structure -->
    <xsd:element name='title'>
        <xsd:complexType>
            <xsd:simpleContent>
                <xsd:extension base='xsd:string'>
                    <xsd:attribute ref='lang'/>
                </xsd:extension>
            </xsd:simpleContent>
        </xsd:complexType>  
    </xsd:element>

    <xsd:element name='book'>
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref='title'/>
                <xsd:element ref='author' maxOccurs='10'/>
                <xsd:element ref='year'/>
                <xsd:element ref='price'/>
                <xsd:element ref='photo' minOccurs='0'/>
            </xsd:sequence>
            <xsd:attribute ref='category'/>
        </xsd:complexType>
    </xsd:element>

    <xsd:element name='bookstore'>
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref='book' maxOccurs='unbounded'/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

</xsd:schema>
  1. 当我最初尝试在初始定义中添加这样的参数(?)作为min / max时,我被拒绝了错误。但是当我将它们添加到相同元素的ref实例时,接受了更改。为什么是这样?在我看来,这些参数应该在初始定义中保持位置?
  2. 澄清我的意思是我遇到了错误:

    <xsd:element name='author' type='xsd:string' maxOccurs='10'/>
    

    但不是:

    <xsd:element ref='author' maxOccurs='10'/>
    
    1. 使用该结构,主要是具有属性&#39; lang&#39;的标题元素。我得到错误的类型字符串是不被允许的,因为它应该说两次,一次在初始的xsd:string spot,再次在complexType中。现在我找到了一个涉及simpleContent和扩展的修复,但我不确定如何修复它。有什么想法吗?
    2. 感谢 - 你!

0 个答案:

没有答案