File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes XML Schema Definition Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML Schema Definition Problem" Watch "XML Schema Definition Problem" New topic

XML Schema Definition Problem

Mingwei Jiang
Ranch Hand

Joined: Feb 19, 2004
Posts: 63
I've encountered a very weird problem when using XML schema. I think the issue lies in the namespace definition, but I cannot figure it out. When I use noNamespaceSchemaLocation, it works fine, but when I defined a target name space, there will be validation errors in eclipse3.1 web tools platform saying "cvc-complex-type.2.4.a: Invalid content was found starting with element 'orderperson'. One of '{"" rderperson}' is expected." Could anyone help me on this?

Below is the sample.xsd file

And sample.xml lies below:

Italic orderperson is where Eclipse says error. Thanks.
Peer Reynders

Joined: Aug 19, 2005
Posts: 2930
Your options are:
  • You can give it what it wants: <orderperson>""</orderperson>
  • You can make the element entirely optional by modifying the Schema: <xs:element name="orderperson" type="xs:string" minOccurs="0" />
  • You have make a major revision your schema to allow an empty element.

  • Something along the lines of (i.e. I didn't try this):

    Your schema requires a string. A string of length zero is an empty string which still needs to be represented as "". Empty content is basically the absence of elements � to have empty content your element has to be a complexType. To contain character data, the complexType contains simpleContent which itself contains an extension of string.
    Mingwei Jiang
    Ranch Hand

    Joined: Feb 19, 2004
    Posts: 63
    Thank you guy! But actually I found the problem lies in the namespace definition. If I define a prefix in the xml file namespace definition and add the prefix to the root element, then it works.

    But why when I try to add that prefix to the subelement, it doesn't work again?
    I agree. Here's the link:
    subject: XML Schema Definition Problem
    It's not a secret anymore!