XML parsing failure - [s4s-elt-invalid-content.1]
I'm having problems while parsing a XML file. The XML schema used is:
<xsd:complexType name="QuoteFIBondPrice">
<xsd:complexContent>
<xsd:sequence>
<xsd:element name="BidPrice" type="QuoteFIBondValue" minOccurs="0"/>
<xsd:element name="MidPrice" type="QuoteFIBondValue" minOccurs="0"/>
<xsd:element name="OfferPrice" type="QuoteFIBondValue" minOccurs="0"/>
<xsd:element name="MaturityDate" type="DbGMLType:SystemName" minOccurs="0"/>
<xsd:element name="Coupon" type="DbGMLType:SystemName" minOccurs="0"/>
<xsd:element name="DisplayName" type="DbGMLType:SystemName" minOccurs="0"/>
</xsd:sequence>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="QuoteFIBondValue">
<xsd:all>
<xsd:element name="QuoteValue" type="DbGMLType:QuoteValue" minOccurs="0"/>
</xsd:all>
</xsd:complexType>
The error message I'm getting is this:
class com.db.dbadapter.util.xml.XMLValidatorParserException: SAXParseException(s) encountered: [s4s-elt-invalid-content.1: The content of 'QuoteFIBondPrice' is invalid. 开发者_JS百科 Element 'sequence' is invalid, misplaced, or occurs too often. (line: 53, column: 18) ]
Could you please give me a hand?
I've changed the XML schema and now it is this way:
<xsd:complexType name="QuoteFIBondPrice">
<xsd:sequence>
<xsd:element name="BidPrice" type="QuoteFIBondValue" minOccurs="0"/>
<xsd:element name="MidPrice" type="QuoteFIBondValue" minOccurs="0"/>
<xsd:element name="OfferPrice" type="QuoteFIBondValue" minOccurs="0"/>
<xsd:element name="MaturityDate" type="DbGMLType:SystemName" minOccurs="0"/>
<xsd:element name="Coupon" type="DbGMLType:SystemName" minOccurs="0"/>
<xsd:element name="DisplayName" type="DbGMLType:SystemName" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="QuoteFIBondValue">
<xsd:all>
<xsd:element name="QuoteValue" type="DbGMLType:QuoteValue" minOccurs="0"/>
</xsd:all>
</xsd:complexType>
After testing, I realised that the previous error has changed to:
**[cvc-complex-type.2.4.a: Invalid content was found starting with element 'BidPrice'. One of '{MaturityDate, Coupon, DisplayName}' is expected. (line: 35, column: 17) ]
[cvc-complex-type.2.3: Element 'BidPrice' cannot have character [children], because the type's content type is element-only. (line: 35, column: 35) ]
[cvc-complex-type.2.3: Element 'MidPrice' cannot have character [children], because the type's content type is element-only. (line: 36, column: 38) ]class com.db.dbadapter.util.xml.XMLValidatorParserException: SAXParseException(s) encountered:
[cvc-complex-type.2.3: Element 'OfferPrice' cannot have character [children], because the type's content type is element-only. (line: 34, column: 39) ]
[cvc-complex-type.2.4.a: Invalid content was found starting with element 'BidPrice'. One of '{MaturityDate, Coupon, DisplayName}' is expected. (line: 35, column: 17) ]
[cvc-complex-type.2.3: Element 'BidPrice' cannot have character [children], because the type's content type is element-only. (line: 35, column: 35) ]
[cvc-complex-type.2.3: Element 'MidPrice' cannot have character [children], because the type's content type is element-only. (line: 36, column: 38) ]**
@Jon, @skaffman, do you have any suggestion?
Many thanks
You don't need the complexContent
element, I don't think, you can just put the sequence
directly under the complexType
:
<xsd:complexType name="QuoteFIBondPrice">
<xsd:sequence>
<xsd:element name="BidPrice" type="QuoteFIBondValue" minOccurs="0"/>
<xsd:element name="MidPrice" type="QuoteFIBondValue" minOccurs="0"/>
<xsd:element name="OfferPrice" type="QuoteFIBondValue" minOccurs="0"/>
<xsd:element name="MaturityDate" type="DbGMLType:SystemName" minOccurs="0"/>
<xsd:element name="Coupon" type="DbGMLType:SystemName" minOccurs="0"/>
<xsd:element name="DisplayName" type="DbGMLType:SystemName" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
See w3schools docs and examples.
I believe it's the schema that's invalid, not the message itself. complexContent
is meant to contain annotations, restrictions or extensions.
Are you sure it's not meant to be just complexType
instead of having a nested complexContent
?
精彩评论