tags:

views:

42

answers:

2

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

A: 

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?

Jon Skeet
Hi Jon. In fact I'm a newbie to XML schemas. You mean I must remove the "complexContent" element? Thanks
darklydreamingcoder
@John: Yes, remove the element but not its contents... see skaffman's answer, basically :)
Jon Skeet
Ok Jon, thanks :)
darklydreamingcoder
Hi Jon, I've edited my question. Unfortunately the error has changed.
darklydreamingcoder
@John: Okay, so now it looks like the schema is valid, but the content doesn't match the schema...
Jon Skeet
The error says "Element 'BidPrice' cannot have character [children], because the type's content type is element-only." I'm trying to figure out the meaning of this message. I think the XML message may be coming on this format:<BidPrice> <another_element> value </another_element> </BidPrice>And in fact it should come on this format:<BidPrice> value </BidPrice>But I'm not sure...
darklydreamingcoder
@John: Yes, that looks like it's probably the problem. You should *definitely* log a copy of the XML so you can try this in a more controlled way.
Jon Skeet
+1  A: 

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.

skaffman
Hi skaffman. Ok, I'll remove the "complexContent" element. But will I need to remove the "sequence" element as well? Thanks
darklydreamingcoder
@John: Umm, no, the sample I posted should work.
skaffman
Nice. I'll correct and make a try. I'll let you know when I have finished. Thank you very much
darklydreamingcoder
Hi skaffman, I've edited my question. Unfortunately the error has changed.
darklydreamingcoder