2015-01-26 113 views
1

我尝试创建XML架构时遇到了一个小问题。 当我生成它时,我得到了这个错误信息: 必须指定一个根元素。XSD:根元素错误

那么问题是什么?

<?xml version="1.0" encoding="UTF-8"?> 

<complexType name="yazartipi"> 
    <sequence> 
     <element name="isim" type="string"></element> 
     <element name="soyad" type="string"></element> 
    </sequence> 
</complexType> 

<complexType name="kitaptipi"> 
    <sequence> 
     <element name="ad" type="string"></element> 
     <element name="sene" type="int"></element> 
     <element name="kategori" type="string"></element> 
     <element name="yazar" type="tns:yazartipi"></element> 
    </sequence> 
    <attribute name="no" type="int" use="required"></attribute> 
</complexType> 

<complexType name="kitaplartipi"> 
    <sequence> 
     <element name="kitap" type="tns:kitaptipi" minOccurs="1" maxOccurs="unbounded"></element> 
    </sequence> 
</complexType> 

<element name="kitaplar" type="tns:kitaplartipi"></element> 

+0

这是你的整个XML架构文件或者是它的提取物? – softwariness 2015-01-26 20:56:38

+0

@softwariness它是我的整个XML模式。我只想尝试如何生成它。但我couldnt:s – 2015-01-26 20:58:58

+0

我已经创建了一个XML模式与您的片段,并没有问题。您能否详细说明您是如何生成它以及在哪个步骤中解决问题的? – 2015-01-26 21:00:07

回答

0

的清理你的XSD后:

<?xml version="1.0" encoding="UTF-8"?> 
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
     targetNamespace="http://www.example.org/Kitaplar" 
     xmlns:tns="http://www.example.org/Kitaplar" 
     elementFormDefault="unqualified" 
     attributeFormDefault="qualified"> 

    <complexType name="yazartipi"> 
    <sequence> 
     <element name="isim" type="string"></element> 
     <element name="soyad" type="string"></element> 
    </sequence> 
    </complexType> 

    <complexType name="kitaptipi"> 
    <sequence> 
     <element name="ad" type="string"></element> 
     <element name="sene" type="int"></element> 
     <element name="kategori" type="string"></element> 
     <element name="yazar" type="tns:yazartipi"></element> 
    </sequence> 
    <attribute name="no" type="int" use="required"></attribute> 
    </complexType> 

    <complexType name="kitaplartipi"> 
    <sequence> 
     <element name="kitap" type="tns:kitaptipi" minOccurs="1" maxOccurs="unbounded"></element> 
    </sequence> 
    </complexType> 

    <element name="kitaplar" type="tns:kitaplartipi"></element> 
</schema> 

你应该找到一个XML文档像这样的:

<?xml version="1.0" encoding="utf-8"?> 
<tns:kitaplar xmlns:tns="http://www.example.org/Kitaplar" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xsi:schemaLocation="http://www.example.org/Kitaplar try.xsd"> 
    <kitap tns:no="0"> 
    <ad/> 
    <sene>1</sene> 
    <kategori/> 
    <yazar> 
     <isim/> 
     <soyad/> 
    </yazar> 
    </kitap> 
</tns:kitaplar> 

将成功验证。

0

答案在消息中。 “根”元素是包装整个文档的元素。

例,无根:

<tag> 
    <value1>V</value1> 
</tag> 
<tag> 
    <value1>X</value1> 
</tag> 

例有根元素:

0

这个答案是基于你在这里把整个.xsd文件的假设。在这种使用情况下,你没有使用过的xs:schema元素定义的模式如下所示:

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

在架构上面我们使用标准的命名空间(XS),和与该命名空间相关联的URI是模式语言定义,其标准值为http://www.w3.org/2001/XMLSchema

您还应该参考以下链接了解详细参考: http://www.w3schools.com/schema/schema_example.asp