2011-06-26 17 views
5

Mam prosty plik XML, który chcę sprawdzić na XSD. Kiedy zatwierdź jakiejś przypadkowej walidator, zawsze pojawia się następujący błąd:Błąd podczas sprawdzania poprawności XML przed XSD

Invalid content was found starting with element 'Entities'. One of '{Entities}' is expected.

Oto XML:

<BusinessModel xmlns="http://schemas.testxyzxyz.de/xyz/BusinessModel" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<Entities> 
    <Entity Name="Customer"> 
     <Attribute Name="Forename" Type="String" /> 
     <Attribute Name="Surname" Type="String" /> 
     <Attribute Name="Birthday" Type="Date" /> 
    </Entity> 
</Entities> 
</BusinessModel> 

jak również xsd:

<?xml version="1.0"?> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     targetNamespace="http://schemas.testxyzxyz.de/xyz/BusinessModel" 
     xmlns="http://schemas.testxyzxyz.de/xyz/BusinessModel"> 

<xsd:element name="BusinessModel" type="BusinessModelType" /> 

<xsd:complexType name="BusinessModelType"> 
    <xsd:choice minOccurs="0" maxOccurs="unbounded"> 
     <xsd:element name="Entities" type="EntitiesType" /> 
    </xsd:choice> 
</xsd:complexType> 

<xsd:complexType name="EntitiesType"> 
    <xsd:sequence> 
     <xsd:element name="Entity" type="EntityType" maxOccurs="unbounded" /> 
    </xsd:sequence> 
</xsd:complexType> 

<xsd:complexType name="AttributeType"> 
    <xsd:attribute name="Name" type="xsd:string" use="required" /> 
    <xsd:attribute name="Type" type="xsd:string" use="required" /> 
</xsd:complexType> 

<xsd:complexType name="EntityType"> 
    <xsd:sequence> 
     <xsd:element name="Attribute" type="AttributeType" maxOccurs="unbounded" minOccurs="1" /> 
    </xsd:sequence> 
     <xsd:attribute name="Name" type="xsd:string" use="required" /> 
</xsd:complexType> 
</xsd:schema> 

Szukasz że Wydawaj od godzin i nadal nie znajduję błędu. Czy możesz wskazać mi właściwy kierunek? ;)

Odpowiedz

3

XML Representation of Element Declaration Schema Components:

{target namespace}

If form is present and its actual value is qualified , or if form is absent and the actual value of elementFormDefault on the <schema> ancestor is qualified , then the actual value of the targetNamespace [attribute] of the parent <schema> element information item, or absent if there is none, otherwise absent.

Ponieważ wartość domyślna elemeFormDefault jest unqualified, o ile nie zaznaczono lokalne elementy muszą być bezwarunkowe inaczej.

Po ustawieniu xmlns="http://schemas.testxyzxyz.de/xyz/BusinessModel" zakwalifikowano Entities. Rozwiązaniem jest ustawienie elementFormDefault="qualified" jako @polishchuk napisał.

+0

Dziękuję, że naprawili problem :) –

0

Spróbuj tego schematu:

<?xml version="1.0"?> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://schemas.testxyzxyz.de/xyz/BusinessModel" xmlns:b="http://schemas.testxyzxyz.de/xyz/BusinessModel"> 
    <xsd:element name="BusinessModel" type="b:BusinessModelType" /> 
    <xsd:complexType name="BusinessModelType"> 
    <xsd:choice minOccurs="0" maxOccurs="unbounded"> 
     <xsd:element name="Entities" type="b:EntitiesType" /> 
    </xsd:choice> 
    </xsd:complexType> 
    <xsd:complexType name="EntitiesType"> 
    <xsd:sequence> 
     <xsd:element name="Entity" type="b:EntityType" maxOccurs="unbounded" /> 
    </xsd:sequence> 
    </xsd:complexType> 
    <xsd:complexType name="AttributeType"> 
    <xsd:attribute name="Name" type="xsd:string" use="required" /> 
    <xsd:attribute name="Type" type="xsd:string" use="required" /> 
    </xsd:complexType> 
    <xsd:complexType name="EntityType"> 
    <xsd:sequence> 
     <xsd:element name="Attribute" type="b:AttributeType" maxOccurs="unbounded" minOccurs="1" /> 
    </xsd:sequence> 
    <xsd:attribute name="Name" type="xsd:string" use="required" /> 
    </xsd:complexType> 
</xsd:schema> 
Powiązane problemy