gpt4 book ai didi

java - 针对 XSD 的 xml 验证 : Invalid content was found starting with element xxx

转载 作者:行者123 更新时间:2023-12-01 04:38:49 25 4
gpt4 key购买 nike

我的 xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<workbook xmlns="http://www.dei.isep.ipp.pt/lapr4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.dei.isep.ipp.pt/lapr4 validate.xsd">
<lastSave>2013/06/05 20:33:23</lastSave>
<numSpreadsheets>3</numSpreadsheets>
<spreadsheet title="Sheet 1">
<cell horizAlign="2" vertiAlign="0" fontStyle="0" fontSize="12" fontName="Dialog" fgColor="-13421773" bgColor="-1" left="1" right="1" top="1" bottom="1" content="a" address="C7" row="6" column="2"/>
<cell horizAlign="2" vertiAlign="0" fontStyle="0" fontSize="12" fontName="Dialog" fgColor="-13421773" bgColor="-1" left="1" right="1" top="1" bottom="1" content="asd" address="A7" row="6" column="0"/>
<cell horizAlign="2" vertiAlign="0" fontStyle="0" fontSize="12" fontName="Dialog" fgColor="-13421773" bgColor="-1" left="1" right="1" top="1" bottom="1" content="ad" address="B5" row="4" column="1"/>
<cell horizAlign="2" vertiAlign="0" fontStyle="0" fontSize="12" fontName="Dialog" fgColor="-13421773" bgColor="-1" left="1" right="1" top="1" bottom="1" content="sad" address="B7" row="6" column="1"/>
</spreadsheet>
<spreadsheet title="Sheet 2"/>
<spreadsheet title="Sheet 3"/>
</workbook>

我的 xsd 文件:

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

<xs:schema xmlns="http://www.dei.isep.ipp.pt/lapr4"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.dei.isep.ipp.pt/lapr4"
elementFormDefault="qualified">

<xs:element name="workbook" type="TWorkbook"/>

</xs:schema>
<xs:complexType name="TWorkbook">
<xs:sequence>
<xs:element name="lastSave" type="xs:string"/>
<xs:element name="numSpreadsheets" type="TnumSpreadsheets" minOccurs="1"/>
<xs:element name="spreadsheet" type="TSpreadSheet" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:simpleType name="TnumSpreadsheets">
<xs:restriction base="xs:int">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="100" />
</xs:restriction>
</xs:simpleType>

<xs:complexType name="TSpreadSheet">
<xs:sequence>
<xs:element name="cell" type="TCell" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="title" type="xs:string" />
</xs:complexType>

<xs:complexType name="TCell">
<xs:attribute name="row" type="xs:int" />
<xs:attribute name="column" type="xs:int" />

<xs:attribute name="horizAlign" type="xs:int" />
<xs:attribute name="vertiAlign" type="xs:int" />

<xs:attribute name="fontStyle" type="xs:int" />
<xs:attribute name="fontSize" type="xs:int" />
<xs:attribute name="font" type="xs:string" />
<xs:attribute name="address" type="xs:string" />
<xs:attribute name="fontName" type="xs:string" />
<xs:attribute name="fgColor" type="xs:int" />
<xs:attribute name="bgColor" type="xs:int" />

<xs:attribute name="left" type="xs:int" />
<xs:attribute name="right" type="xs:int" />
<xs:attribute name="top" type="xs:int" />
<xs:attribute name="bottom" type="xs:int" />

<xs:attribute name="content" type="xs:string" />
</xs:complexType>

</xs:schema>

我在 Web 和 NetBeans 上逐一验证了该文件,并相互验证,但是当我运行该应用程序时,我总是收到此错误:

org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'lastSave'. One of '{"http://www.dei.isep.ipp.pt/lapr4":numSpreadsheets}' is expected.

我一直在寻找这个问题的答案,但似乎没有任何效果,有人能给我一些关于这个问题的线索吗?

提前致谢。

最佳答案

您拥有 </xs:schema> 的两倍XSD 文件中的结束标记。尝试删除第一次出现的情况,它会使 XSD 处理器感到困惑。

此外,您还缺少 <cell /> <spreadsheet /> 中的元素标签添加底部。

<小时/>

这验证了一切正确:

XML:

<?xml version="1.0" encoding="UTF-8"?>
<workbook xmlns="http://www.dei.isep.ipp.pt/lapr4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.dei.isep.ipp.pt/lapr4 validate.xsd">
<lastSave>2013/06/05 20:33:23</lastSave>
<numSpreadsheets>3</numSpreadsheets>
<spreadsheet title="Sheet 1">
<cell horizAlign="2" vertiAlign="0" fontStyle="0" fontSize="12" fontName="Dialog" fgColor="-13421773" bgColor="-1" left="1" right="1" top="1" bottom="1" content="a" address="C7" row="6" column="2"/>
<cell horizAlign="2" vertiAlign="0" fontStyle="0" fontSize="12" fontName="Dialog" fgColor="-13421773" bgColor="-1" left="1" right="1" top="1" bottom="1" content="asd" address="A7" row="6" column="0"/>
<cell horizAlign="2" vertiAlign="0" fontStyle="0" fontSize="12" fontName="Dialog" fgColor="-13421773" bgColor="-1" left="1" right="1" top="1" bottom="1" content="ad" address="B5" row="4" column="1"/>
<cell horizAlign="2" vertiAlign="0" fontStyle="0" fontSize="12" fontName="Dialog" fgColor="-13421773" bgColor="-1" left="1" right="1" top="1" bottom="1" content="sad" address="B7" row="6" column="1"/>
</spreadsheet>
<spreadsheet title="Sheet 2"><cell /></spreadsheet>
<spreadsheet title="Sheet 2"><cell /></spreadsheet>
</workbook>

XSD:

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

<xs:schema xmlns="http://www.dei.isep.ipp.pt/lapr4"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.dei.isep.ipp.pt/lapr4"
elementFormDefault="qualified">

<xs:element name="workbook" type="TWorkbook"/>

<xs:complexType name="TWorkbook">
<xs:sequence>
<xs:element name="lastSave" type="xs:string"/>
<xs:element name="numSpreadsheets" type="TnumSpreadsheets" minOccurs="1"/>
<xs:element name="spreadsheet" type="TSpreadSheet" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:simpleType name="TnumSpreadsheets">
<xs:restriction base="xs:int">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="100" />
</xs:restriction>
</xs:simpleType>

<xs:complexType name="TSpreadSheet">
<xs:sequence>
<xs:element name="cell" type="TCell" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="title" type="xs:string" />
</xs:complexType>

<xs:complexType name="TCell">
<xs:attribute name="row" type="xs:int" />
<xs:attribute name="column" type="xs:int" />

<xs:attribute name="horizAlign" type="xs:int" />
<xs:attribute name="vertiAlign" type="xs:int" />

<xs:attribute name="fontStyle" type="xs:int" />
<xs:attribute name="fontSize" type="xs:int" />
<xs:attribute name="font" type="xs:string" />
<xs:attribute name="address" type="xs:string" />
<xs:attribute name="fontName" type="xs:string" />
<xs:attribute name="fgColor" type="xs:int" />
<xs:attribute name="bgColor" type="xs:int" />

<xs:attribute name="left" type="xs:int" />
<xs:attribute name="right" type="xs:int" />
<xs:attribute name="top" type="xs:int" />
<xs:attribute name="bottom" type="xs:int" />

<xs:attribute name="content" type="xs:string" />
</xs:complexType>

</xs:schema>

关于java - 针对 XSD 的 xml 验证 : Invalid content was found starting with element xxx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16949313/

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