开发者

xml validation problem

I'm having trouble validating a schema I created. "cvc-elt.1: Cannot find the declaration of element 'category'."

xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="list">
<xs:complexType>
    <xs:sequence>
        <xs:element name="category" type="categoryType" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
</xs:complexType>
</xs:element>

<xs:complexType name="categoryType">
    <xs:sequence>
        <xs:element name="name" type="xs:string"/>
        <xs:element name="desc"  type="xs:string"/>
        <xs:element name="icon" type="xs:base64Binary"/>
        <xs:element name="poi" type="poiType"  minOccurs="0"  maxOccurs="unbounded"/>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="poiType">
    <xs:sequence>
        <xs:element name="name" type="xs:string"/>
        <xs:element name="desc"  type="xs:string"/>
        <xs:element name="longitude"  type="xs:long"/>
        <xs:element name="latitude"  type="xs:long"/>
        <xs:element name="url" type="xs:string" minOccurs="0"  maxOccurs="unbounded"/>
        <xs:element name="image" type="xs:base64Binary" minOccurs="0"  maxOccurs="unbounded"/>  
    </xs:sequence>
</xs:complexType>

</xs:schema>

xml

<?xml version="1.0" encoding="UTF-8"?>
<list SchemaLocation="sem.xsd">

<category>

<name>Sehenswürdigkeiten</name>
<desc>sehenswerte und berühmte Orte, die man gesehen haben muss</desc>
<icon>...</icon>

<poi>
<name>Linzer Landhaus</name>
<desc>Sitz des Oberösterreichsichen Landtags</desc>
<url>http://www.linz.at/tourismus/7569.asp</url>
<longitude>48.304107</longitude>
<latitude>14.286025</latitude>
<image>...</image>
</poi>

<poi>
<name>Ars Electronica</name>
<desc>Museum der digitalen Künste</desc>
<url>http://www.aec.at&开发者_StackOverflow社区lt;/url>
<longitude>48.309788</longitude>
<latitude>14.284179</latitude>
<image>...</image>
<image>...</image>
</poi>

</category>

<category>...</category>

</list>

any idea whats wrong? cheers hoax


The problem is probably with the line:

<list SchemaLocation="sem.xsd">

You haven't indicated that SchemaLocation is anything special, it just looks like another attribute.

It should be:

<list xsi:schemaLocation="sem.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

See here for a more detailed explanation.


<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="sem.xsd">

does the trick =)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜