gpt4 book ai didi

java - XSD:根元素错误

转载 作者:太空宇宙 更新时间:2023-11-04 14:12:25 25 4
gpt4 key购买 nike

当我尝试创建 XML 模式时遇到一个小问题。当我生成它时,我收到以下错误消息:必须指定根元素。

那么问题出在哪里呢?

<?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>

最佳答案

清理 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>

将成功验证。

关于java - XSD:根元素错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28158467/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com