Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do I handle repeated element names

843834Aug 5 2008 — edited Aug 6 2008
I am trying to use javax.xml to validate my xml against my schema. The problem is that if I have a schema like this:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:wmh="http://www.wmhelp.com/2003/eGenerator"
   elementFormDefault="qualified">
    <xs:element name="aLife">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="x"/>
                <xs:element ref="y"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
 
    <xs:element name="x">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="repeated" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="y">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="repeated" type="multistrings"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="multistrings">
       <xs:sequence>
          <xs:element name="value" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
       </xs:sequence>
    </xs:complexType>
</xs:schema>
Note, in my schema there are actually other elements in the sequences that have been removed for brevity. The validator will throw an error when I use the syntax required for the 'repeated' element inside 'y'. I get an error like this:

Element 'repeated' cannot have character [children], because the type's content type is element-only.

Is this a problem with my schema or something else?

Edited by: miteke on Aug 5, 2008 1:48 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 3 2008
Added on Aug 5 2008
5 comments
408 views