Xml MaxOccurs、无效内容等-架构

Xml MaxOccurs、无效内容等-架构,xml,schema,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 l

好的,最初的查询是固定的,但我仍然有一些我感到困惑的地方

以下是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>

日常意大利语
吉娅达·德·劳伦蒂斯
2005
30
http://puu.sh/gNzTB/258d022e33.jpg
哈利·波特
J K.罗琳
2005
29.99
http://puu.sh/gNzV9/e27dfc1b55.jpg
XQuery启动
詹姆斯·麦戈文
伯特纳
库尔特·卡格尔
詹姆斯·林恩
瓦迪亚纳坦·纳加拉扬
2003
49.99
学习XML
埃里克·T·雷
2003
39.95
模式如下:

<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>

  • 当我最初尝试在初始定义中添加诸如min/max这样的参数(?)时,我被错误所拒绝。但是当我将它们添加到相同元素的ref实例时,这些更改被接受了。为什么会这样?在我看来,这样的参数应该在最初的定义中占有一席之地
  • 为了澄清,我的意思是我在以下方面有错误:

    <xsd:element name='author' type='xsd:string' maxOccurs='10'/>
    
    
    
    但不包括:

    <xsd:element ref='author' maxOccurs='10'/>
    
    
    
  • 对于这个结构,主要是带有属性“lang”的title元素,我得到了类型string不允许的错误,因为它应该被声明了两次,一次是在初始xsd:string位置,另一次是在complexType中。现在我找到了一个涉及simpleContent和扩展的修复方法,但我不确定它是如何修复的。有什么想法吗

  • 谢谢大家!

    如果您已经在模式中执行了一些更正,请发布它并解释仍然存在的问题。谢谢。我建议你只关注一个问题。目前,问题的变化太快了,所以尝试回答是不明智的。好吧,我重温了整个帖子,现在应该更清楚了。