验证时不确定XML和XSD错误

时间:2016-01-16 03:24:39

标签: xml xsd xml-validation

我无法让我的文件验证。

以下是我遇到的错误。

-Errors in the XML document:
    9:  23  cvc-complex-type.2.4.d: Invalid content was found starting with element 'boardrelationships'. No child element is expected at this point.
    25: 23  cvc-complex-type.2.4.d: Invalid content was found starting with element 'boardrelationships'. No child element is expected at this point.
    40: 23  cvc-complex-type.2.4.d: Invalid content was found starting with element 'boardrelationships'. No child element is expected at this point.
    54: 23  cvc-complex-type.2.4.d: Invalid content was found starting with element 'boardrelationships'. No child element is expected at this point.
    67: 23  cvc-complex-type.2.4.d: Invalid content was found starting with element 'boardrelationships'. No child element is expected at this point.

-Errors in file xml-schema:
    11: 62  s4s-elt-must-match.1: The content of 'Name' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: element.

我将在下面发布我的XML文档代码和我的XSD架构。我对此很陌生,所以我不确定自己做错了什么。我已经改变了我的文件的格式,但我仍然得到相同的错误......

<?xml version="1.0"?>
<KeyExecutives>
    <KeyExecutive>
        <Name>
            <first>Lawrence</first>
            <middle>Edward</middle>
            <last>Page</last>
        </Name>
        <boardrelationships>22</boardrelationships>
        <titles>
            <title>Co-Founder</title>
            <title>Chief Executive officer</title>
            <title>Director</title>
            <title>Member of Acquisition Committee</title>
            <title>Member of Executive Committee</title>
        </titles>
        <age>42</age>
    </KeyExecutive>
    <KeyExecutive>
        <Name>
            <first>Sergey</first>
            <middle></middle>
            <last>Brin</last>
        </Name>
        <boardrelationships>22</boardrelationships>
        <titles>
            <title>Co-Founder</title>
            <title>Director</title>
            <title>Member of Acquisition Committee</title>
            <title>Member of Executive Committee</title>
        </titles>
        <age>41</age>
    </KeyExecutive>
    <KeyExecutive>
        <Name>
            <first>Eric</first>
            <middle>E.</middle>
            <last>Schmidt Ph.D.</last>
        </Name>
        <boardrelationships>137</boardrelationships>
        <titles>
            <title>Executive Chairman</title>
            <title>Chairman of Executive Committee</title>
            <title>Chairman of Acquisition Committee</title>
        </titles>
        <age>60</age>
    </KeyExecutive>
    <KeyExecutive>
        <Name>
            <first>Ruth</first>
            <middle>M.</middle>
            <last>Porat</last>
        </Name>
        <boardrelationships>10</boardrelationships>
        <titles>
            <title>Chief Financial Officer</title>
            <title>Senior Vice President</title>
        </titles>
        <age>58</age>
    </KeyExecutive>
    <KeyExecutive>
        <Name>
            <first>Meir</first>
            <middle></middle>
            <last>Brand</last>

<?xml version="1.0"?>
<!-- XSD Schema for complex_apoole33_IT_MUST_VALIDATE.xml -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="KeyExecutives">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="KeyExecutive" maxOccurs="unbounded">
      <xsd:complexType>
        <xsd:sequence>
              <xsd:element name="Name">
                <xsd:element name="first" type="xsd:string"/>
        <xsd:element name="middle" type="xsd:string" minOccurs="0"/>
        <xsd:element name="last" type="xsd:string"/>
              <xsd:element name="boardrelationships" type="xsd:integer" minOccurs="0"/>
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="titles">
                    <xsd:element name="title" type="xsd:string" maxOccurs="unbounded"/>
              <xsd:element name="age" type="xsd:integer" minOccurs="0"/>
              </xsd:element>
                </xsd:sequence>
              </xsd:complexType>
              </xsd:element>
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

1 个答案:

答案 0 :(得分:2)

通过以下(众多结构)修复XSD(以及消除XML中的截止元素),您的XML现在将成功针对您的XSD进行验证:

XML

<?xml version="1.0"?>
<KeyExecutives>
  <KeyExecutive>
    <Name>
      <first>Lawrence</first>
      <middle>Edward</middle>
      <last>Page</last>
    </Name>
    <boardrelationships>22</boardrelationships>
    <titles>
      <title>Co-Founder</title>
      <title>Chief Executive officer</title>
      <title>Director</title>
      <title>Member of Acquisition Committee</title>
      <title>Member of Executive Committee</title>
    </titles>
    <age>42</age>
  </KeyExecutive>
  <KeyExecutive>
    <Name>
      <first>Sergey</first>
      <middle></middle>
      <last>Brin</last>
    </Name>
    <boardrelationships>22</boardrelationships>
    <titles>
      <title>Co-Founder</title>
      <title>Director</title>
      <title>Member of Acquisition Committee</title>
      <title>Member of Executive Committee</title>
    </titles>
    <age>41</age>
  </KeyExecutive>
  <KeyExecutive>
    <Name>
      <first>Eric</first>
      <middle>E.</middle>
      <last>Schmidt Ph.D.</last>
    </Name>
    <boardrelationships>137</boardrelationships>
    <titles>
      <title>Executive Chairman</title>
      <title>Chairman of Executive Committee</title>
      <title>Chairman of Acquisition Committee</title>
    </titles>
    <age>60</age>
  </KeyExecutive>
  <KeyExecutive>
    <Name>
      <first>Ruth</first>
      <middle>M.</middle>
      <last>Porat</last>
    </Name>
    <boardrelationships>10</boardrelationships>
    <titles>
      <title>Chief Financial Officer</title>
      <title>Senior Vice President</title>
    </titles>
    <age>58</age>
  </KeyExecutive>
</KeyExecutives>

XSD

<?xml version="1.0"?>
<!-- XSD Schema for complex_apoole33_IT_MUST_VALIDATE.xml -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="KeyExecutives">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="KeyExecutive" maxOccurs="unbounded">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="Name">
                <xsd:complexType>
                  <xsd:sequence>                
                    <xsd:element name="first" type="xsd:string"/>
                    <xsd:element name="middle" type="xsd:string" minOccurs="0"/>
                    <xsd:element name="last" type="xsd:string"/>
                  </xsd:sequence>
                </xsd:complexType>
              </xsd:element>
              <xsd:element name="boardrelationships" type="xsd:integer" minOccurs="0"/>
              <xsd:element name="titles">
                <xsd:complexType>
                  <xsd:sequence>                
                    <xsd:element name="title" type="xsd:string" maxOccurs="unbounded"/>
                  </xsd:sequence>
                </xsd:complexType>
              </xsd:element>
              <xsd:element name="age" type="xsd:integer" minOccurs="0"/>
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>