当我尝试创建XML Schema时,我遇到了一个小问题。 当我生成它时,我收到此错误消息: 必须指定根元素。
那么问题是什么?
<?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 :(得分: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>
将成功验证。
答案 1 :(得分:0)
答案在信息中。 A&#34; root&#34; element是一个包装整个文档的元素。
没有root的示例:
<tag>
<value1>V</value1>
</tag>
<tag>
<value1>X</value1>
</tag>
根元素的示例:
<tags>
<tag>
<value1>V</value1>
</tag>
<tag>
<value1>X</value1>
</tag>
</tags>
答案 2 :(得分: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