gpt4 book ai didi

java - XML验证: Invalid content was found starting with element

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

我面临这个问题,但无法解决。我有这个xsd OFX.xsd 。我想用这个模式验证的 xml 如下

<?xml version="1.0"?>
<OFX>
<SIGNONMSGSRSV1>
<SONRS>
<STATUS>
<CODE>0</CODE>
<SEVERITY>INFO</SEVERITY>
</STATUS>
<DTSERVER>20120716233626.570[-7:PDT]</DTSERVER>
<LANGUAGE>ENG</LANGUAGE>
<FI>
<ORG>Symitar</ORG>
<FID>01182</FID>
</FI>
<INTU.BID>01182</INTU.BID>
<INTU.USERID>66983</INTU.USERID>
</SONRS>
</SIGNONMSGSRSV1>
<BANKMSGSRSV1>
<STMTTRNRS>
<TRNUID>0</TRNUID>
<STATUS>
<CODE>0</CODE>
<SEVERITY>INFO</SEVERITY>
</STATUS>
<STMTRS>
<CURDEF>USD</CURDEF>
<BANKACCTFROM>
<BANKID>
</BANKID>
<ACCTID>66983-S80</ACCTID>
<ACCTTYPE>CHECKING</ACCTTYPE>
</BANKACCTFROM>
<BANKTRANLIST>
<DTSTART>20120501</DTSTART>
<DTEND>20120716</DTEND>
<STMTTRN>
<TRNTYPE>FEE</TRNTYPE>
<DTPOSTED>20120713135400</DTPOSTED>
<TRNAMT>-25.00</TRNAMT>
<FITID>30403620120713WF</FITID>
<NAME>Account Transaction</NAME>
<MEMO>Withdrawal Fee</MEMO>
</STMTTRN>
</BANKTRANLIST>
<LEDGERBAL>
<BALAMT>-254.64</BALAMT>
<DTASOF>20120716233626</DTASOF>
</LEDGERBAL>
<AVAILBAL>
<BALAMT>-254.64</BALAMT>
<DTASOF>20120716233626</DTASOF>
</AVAILBAL>
</STMTRS>
</STMTTRNRS>
</BANKMSGSRSV1>
</OFX>

当我尝试在线或使用 java 代码验证此 xml 时。我收到以下错误。

cvc-complex-type.2.4.d: Invalid content was found starting with element 'SEVERITY'
cvc-complex-type.2.4.d: Invalid content was found starting with element 'DTSERVER'
cvc-complex-type.2.4.d: Invalid content was found starting with element 'FID'
and so on....

请告诉我 xsd 中的错误是什么。

最佳答案

您可以选择多种类型

<xs:complexType name="SONRS">
<xs:choice>
<xs:element name="STATUS" type="STATUS" minOccurs="0"
maxOccurs="1" />
<xs:element name="DTSERVER" type="xs:string" minOccurs="0"
maxOccurs="1" />
<xs:element name="LANGUAGE" type="xs:string" minOccurs="0"
maxOccurs="1" />
<xs:element name="DTPROFUP" type="xs:string" minOccurs="1"
maxOccurs="1" />
<xs:element name="DTACCTUP" type="xs:string" minOccurs="0"
maxOccurs="1" />
<xs:element name="FI" type="FI" minOccurs="0" maxOccurs="1" />
</xs:choice>
</xs:complexType>

状态也是如此。因此,您应该仅在 SONRS 的 xml 中包含其中一个元素,如果包含 STATUS,则您将拥有:

<xs:complexType name="STATUS">
<xs:choice>
<xs:element name="CODE" type="xs:integer" minOccurs="0"
maxOccurs="1" />
<xs:element name="SEVERITY" type="xs:string" minOccurs="0"
maxOccurs="1" />
<xs:element name="MESSAGE" type="xs:string" minOccurs="0"
maxOccurs="1" />
</xs:choice>
</xs:complexType>

因此您应该包含 CODE 或 SEVERITY 或 MESSAGE。

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

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