DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: xsd: one of two childelements required, no repetition

  1. #1
    Join Date
    Nov 2008

    xsd: one of two childelements required, no repetition

    Hi all

    I'm looking for a shema solution since a while. The idea is to have one parent element which stores 2 elements of different name. At least one of them must occur, but it is not defined which. It must not be possible to repeat one element twice (child1 should occurs maximum once).

    My idea is something like this:
    <xs:element name="parent">
    			<xs:choice maxOccurs="2">
    				<xs:element name="child1" minOccurs="0"/>
    				<xs:element name="child2" minOccurs="0"/>
    Generating a sample xml with XMLSpy shows, that this doesn't work.
    Wrong in the example xml is:
    it is
    • possible to repeat child1 (or child2) two times
    • it is possible to declare a parent without child elements

    Do you have an idea how to solve this problem?

    Thank you.

    Kind regards

  2. #2
    Join Date
    Nov 2008

    solution with dtd

    I've found a solution using a dtd. Do you know a way how to do this with a shema?

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE grandparent [ 
    	<!ELEMENT grandparent (parent*)> 
    	<!ELEMENT parent (child1 | child2 | (child1,child2))> 
    	<!ELEMENT child1 (#PCDATA)> 
    	<!ELEMENT child2 (#PCDATA)> 

Similar Threads

  1. C++,Unix Professionals required for CADENCE India
    By sapphirecs in forum Careers
    Replies: 0
    Last Post: 12-06-2006, 02:36 PM
  2. entity references in XSD definitions?
    By unknown in forum XML
    Replies: 0
    Last Post: 04-02-2002, 12:15 PM
  3. Replies: 1
    Last Post: 09-07-2001, 03:03 PM
  4. Replies: 1
    Last Post: 09-07-2001, 03:03 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center